如何在html文件中添加脚本标签,在jquery.js被包含之后,但在结束正文标签之前只使用javascript
How to add script tag in the html file after where jquery.js is included but before ending body tag using javascript only?
<html>
...
<body>
...
<script src="jquery.js"></script>
// script tag should be added here
</body>
</html>
我知道标签可以用appendChild()方法添加,但我不确定它会在我想要的地方添加新的脚本标签。任何建议吗? ?
在你想要的地方添加。
function add( url ) {
var elem = document.createElement( 'script' );
elem.setAttribute( 'src', url );
document.body.appendChild( elem );
}