动态创建script标签

时间:2022-04-16 14:55:25
var script = $('<script src="....."></script>');   //创建script标签
$('body').append(script); //将标签插入body尾部

 
 
var head = document.getElementsByTagName('head')[0];var script = document.createElement('script');script.type = 'text/javascript';script.src = 'a.js';head.appendChild(script);
var s = document.createElement("SCRIPT");s.type = "text/javascript";s.innerHTML = "your code";document.getElemnetsByTagName("HEAD")[0].appendChild(s);
window.onload = function(){var scpt = document.createElement("SCRIPT");scpt.type = "text/javascript";scpt.src = "en.js";document.getElemnetsByTagName("HEAD")[0].appendChild(scpt);//使用延时处理setTimeout(function(){   alert(syslang["en"].a);//  -->保证时时有;},1).}
var script = document.createElement("script");    script.src = "//url.com/jquery.js";var s = document.getElementsByTagName("script")[0];s.parentNode.insertBefore(script, s);
var script=$('<script>alert("I am a script element")<\/script>');$('body').append(script);
注意那个转义符号,这个是关键