关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

js中添加script

发布时间:2020-08-28 17:31:55

在开发中可能遇到需要使用到某个js里的方法,但是页面是后端返回的,不方便让后端添加js的时候(同一个页面的模版可能多个页面使用,只有一个页面需要引入js时,最好不要修改模版),可以通过js代码进行添加:


var secScript = document.createElement("script");

secScript.setAttribute("type", "text/javascript");

secScript.setAttribute("src", "https://xxx.xxxxxx.com/xxxxxxxx.js");

document.body.insertBefore(secScript, document.body.lastChild);



/template/Home/Zkeys/PC/Static