jQuery.replaceWith不采取&LT;脚本&GT;标签 [英] jQuery.replaceWith doesn't take <script> tags
本文介绍了jQuery.replaceWith不采取&LT;脚本&GT;标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Ajax响应,其中包含一些HTML,包括&LT;脚本&GT;
元素
I have an AJAX response that contains some HTML, including <script>
elements.
这个HTML应该替换现有的元素,但是当我使用:
This HTML should replace an existing element, but when I use:
$(element).replaceWith($(response))
我失去了脚本标记从它...
I lose the script tags from it...
我如何可以将它究竟是如何发送的HTML?
How can I insert the HTML exactly how it is sent?
推荐答案
这code是Facebook的示例应用程序。插入&LT; DIV ID =FB-根&GT;&LT; / DIV&GT;
在文档中。在code要求jQuery来加载脚本。在你的情况下,更换 //连接..... / all.js的
与&LT;脚本&GT;
元素。
This code is from facebook's sample app. Insert <div id="fb-root"></div>
in your document. The code requires jQuery to load up the script. In your case, replace //connect...../all.js
' with the <script>
elements.
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
这篇关于jQuery.replaceWith不采取&LT;脚本&GT;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文