【发布时间】:2022-01-06 15:36:21
【问题描述】:
我想在网页中动态包含一个脚本标签,但是我无法控制它的 src,所以 src="source.js" 可能看起来像这样。
document.write('<script type="text/javascript">')
document.write('alert("hello world")')
document.write('</script>')
document.write('<p>goodbye world</p>')
现在通常放
<script type="text/javascript" src="source.js"></script>
在头部工作正常,但有没有其他方法可以使用 innerHTML 之类的东西动态添加 source.js?
【问题讨论】:
-
经过数小时苦苦挣扎的 postscribe 是解决方案! https://github.com/krux/postscribe/
标签: javascript src document.write