在html中如何调用指定页面的指定div标签内的指定内容?
展开全部
我先假设不跨域吧。然后使用jQuery
index.html,网络地址http://localhost/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<script>
$(document).ready(function() {
$.get('page.html', function(data) {
var content = $(data).find('.content').html()
$('body').append(content)
})
})
</script>
</body>
</html>
page.html ,网络地址http://localhost/page.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id='content'>index.html运行的时候我会被显示过去</div>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询