动态加载js
动态加载js
1 function loadJs(jssrc, callback) { 2 if (jssrc) { 3 var head = document.getElementsByTagName('head')[0]; 4 var script = document.createElement('script'); 5 if (script.readyState) { //IE 6 script.onreadystatechange = function () { 7 if (script.readyState == "loaded" || script.readyState == "complete") { 8 script.onreadystatechange = null; 9 if (callback && typeof callback == 'function') { 10 callback(); 11 } 12 } 13 }; 14 } else { //Others 15 script.onload = function () { 16 if (callback && typeof callback == 'function') { 17 callback(); 18 } 19 } 20 } 21 script.src = jssrc; 22 head.appendChild(script); 23 } 24 }