.append 使用 jQuery 进行 .load 的内容
我有一个像这样的网页:
<html>
<head>
. . .
</head>
<body>
<div id="wrapper">
<p>Lots of content here!</p>
</div>
</body>
</html>
我还有一个像这样的外部文件:
<div id="more-stuff"><p>Even more content!</p></div>
我想要的是有一个像这样的网页:
<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>
使用 jQuery。我的猜测是这样的:
$(document).ready(function(){
$('#wrapper').append.load('/external.htm');
});
但这行不通,而且我似乎找不到好的解决方案。
I have a webpage like:
<html>
<head>
. . .
</head>
<body>
<div id="wrapper">
<p>Lots of content here!</p>
</div>
</body>
</html>
I also have an external file like this:
<div id="more-stuff"><p>Even more content!</p></div>
What I want is for to have a webpage like this:
<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>
Using jQuery. My guess is something like this:
$(document).ready(function(){
$('#wrapper').append.load('/external.htm');
});
But it won't work and I can't seem to find a good solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样的操作:
它告诉 jQuery 请求 html 文件,然后在准备好时运行回调(依次附加请求返回的数据)。
Try something like this:
It tells jQuery to request the html file, and then to run the callback (which in turn appends the data returned by the request) when it is ready.
.append()
不能那样工作。它需要附加文本。但是.load()
会覆盖其目标的内容,因此您需要首先附加一个子项,然后加载到该子项。.append()
doesn't work that way. It needs text to append. But.load()
overwrites the contents of its target, so you need to first append a child, then load to that child.