当前位置:编程学习 > JS >>

js动态加载外部js文件的方法

下面我们介绍一下关于如何动态加载其它js文件的方法,有需要的朋友可以参考是否好用啊。

(function (clover) {
clover.loadScript = function loadScript(url, callback) {
var heads = document.getElementsByTagName('head');
if (heads.length == 0) {
alert("page must have one head element");
}
var head = heads[0];
var script = document.createElement('script');
script.type = 'text/网页特效';
script.src = url;
// most browsers
script.onload = callback;
// IE 6 & 7
script.onreadystatechange = function () {
if (this.readyState == 'complete') {
callback();
}
}
head.appendChild(script);
}

})(window.clover = window.clover || {});

// sample 使用方法

// clover.loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js");
补充:网页制作,js教程 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,