我有一个像这样的网页:
<html>
<head>
. . .
</head>
<body>
<div id="wrapper">
<p>Lots of content here!</p>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我也有一个像这样的外部文件:
<div id="more-stuff"><p>Even more content!</p></div>
Run Code Online (Sandbox Code Playgroud)
我想要的是拥有这样的网页:
<html>
<head>
. . .
</head>
<body>
<div id="wrapper">
<p>Lots of content here!</p>
<div id="more-stuff"><p>Even more content!</p></div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
使用jQuery.我的猜测是这样的:
$(document).ready(function(){
$('#wrapper').append.load('/external.htm');
});
Run Code Online (Sandbox Code Playgroud)
但它不起作用,我似乎无法找到一个好的解决方案.
尝试这样的事情:
$(document).ready(function(){
$.get('/external.htm', function(data) {
$('#wrapper').append(data);
});
});
Run Code Online (Sandbox Code Playgroud)
它告诉jQuery请求html文件,然后在准备就绪时运行回调(它反过来追加请求返回的数据).