DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> 動態加載外部javascript文件的函數代碼分享
動態加載外部javascript文件的函數代碼分享
編輯:關於JavaScript     
復制代碼 代碼如下:
(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/javascript';
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");
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved