Posted in Javascript onJuly 28, 2011
(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");
动态加载外部javascript文件的函数代码分享
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@