gpt4 book ai didi

jquery - 尝试 jQuery wrapAll 似乎将内容包装两次

转载 作者:行者123 更新时间:2023-12-01 01:30:23 24 4
gpt4 key购买 nike

我的标记如下所示:

<body>
<...
a lot of tags from the web site
...>
<script type="text/javascript" src="http://cdn.jquerytools.org/1.1.1/jquery.tools.min.js"></script>
<script type="text/javascript" src="my_script.js"></script>
<body>

我希望事情是这样的:

<body>
<div id="body-content">
<...
a lot of tags from the web site
...>
<script type="text/javascript" src="http://cdn.jquerytools.org/1.1.1/jquery.tools.min.js"></script>
<script type="text/javascript" src="my_script.js"></script>
</div>
<div id="isolated-component">
</div>
<body>

因此我可以填充 #isolated-component 并轻松地从 jQuery 选择中丢弃它们。

我试过了:

jQuery("body").children().wrapAll("<div id='body-content'></div>")
.after("<div id='isolated-component'></div>");

但最终结果是:

<html>
<head>
<body>
<div id="body-content">
<div id="body-content">
<... page content ...>
</div>
<div id="isolated-component"/>
<div id="isolated-component"/>
</div>
<script src="my_script.js" type="text/javascript">
</script>
</body>
<div id="_firebugConsole" style="display: none;" FirebugVersion="1.4.3" methodName="log"/>
</html>

最佳答案

好的,我找到原因了。当你将body内容移动到DIV时,它会移动脚本标签,包括移动内容的JS,并导致脚本第二次执行。现在我不知道为什么这不会以无限循环结束,但很高兴知道:永远不要移动脚本标签,你会让它们重新加载。

关于jquery - 尝试 jQuery wrapAll 似乎将内容包装两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1543249/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com