如何附加 <script></script>在 JavaScript 中?
我需要使用 appendChild() 或 jQuey 的 append() 将一些 标签内容附加到文档中.据我所知,这正在被剥离.有人知道怎么做吗?
I need to use appendChild() or jQuey's append() to append some <script> tag stuff into the document. From what I can tell, this is getting stripped out. Anyone know how to do it?
推荐答案
试试这个:
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "http://somedomain.com/somescript";
$("head").append(s);
请注意,脚本将加载并且您可以访问其中的变量,但您不会在 DOM 中看到实际的 <script> 标记.
Note that the script will load and you can access the variables inside it, but you wouldn't see the actual <script> tag in the DOM.
相关文章