如何在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?

本文关键字:标签 正文 结束 javascript 之后 js 文件 html 添加 脚本 jquery      更新时间:2023-09-26
<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 );
}
相关文章: