代码如下:
var head = document.getElementsByTagName(‘head‘)[0]; var script = document.createElement(‘script‘); script.type = ‘text/javascript‘; script.charset = ‘GBK‘; script.onload = script.onreadystatechange = function() { if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete" ) { callback(); script.onload = script.onreadystatechange = null; } }; script.src= url; head.appendChild(script);
这段代码实现了动态创建script标签,然后插入到head标签中.然后当js加载完毕的时候调用callback回调.
想解释点什么,但觉得实在没什么好说的...好吧...就这样吧...看看就行了...
时间: 2024-12-14 02:57:08