//加载新的js function _GetJsData(url, callback) { var scripts = document.createElement("script"); document.body.appendChild(scripts); scripts.onload = function() { callback(); document.body.removeChild(this); }; scripts.onreadystatechange = function() { if (this.readyState == "loaded") { callback(); document.body.removeChild(this); } }; scripts.charset = "GBK"; scripts.src = url; } //加载新的js function GetJsData(src,callback){ var head=document.getElementsByTagName("head")[0]; var js=document.createElement("script"); js.setAttribute("src",src); js.onload=js.onreadystatechange=function(){ if(!this.readyState||this.readyState=="loaded"||this.readyState=="complete"){ head.removeChild(js); if(callback) callback(); } } head.appendChild(js); }
VeryCD的
if (typeof(VeryCD) != "object") { var VeryCD = {} } VeryCD.is_ie = navigator.appName == "Microsoft Internet Explorer" ? true: false; VeryCD.$import = function(jsfile, onloadfun, defer) { VeryCD._IMPORT_JSFILE = VeryCD._IMPORT_JSFILE || {}; if (!VeryCD._IMPORT_JSFILE[jsfile]) { var s = "script"; VeryCD._IMPORT_JSFILE[jsfile] = 1; var obj = document.createElement("script"); obj.src = jsfile; if (defer) { obj.defer = "defer"; obj.setAttribute("defer", "defer") } if (onloadfun) { if (typeof onloadfun != "function") { var onloadfunstr = onloadfun; onloadfun = function() { try { eval(onloadfunstr) } catch(e) {} } } if (VeryCD.is_ie) { obj.onreadystatechange = function() { if (this.readyState == "complete" || this.readyState == "loaded") { onloadfun() } } } else { obj.onload = onloadfun } } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(obj, s) } }; VeryCD.$import('http://j.ssajax.cn/js/quote/jquery/jquery-1.5.1.min.js',ok,false); function ok(){$('#test').html('is ok');alert('is ok');};
百度tangram的
baidu.script = baidu.script || {}; baidu.script._createScriptTag = function(scr, url, charset){ scr.setAttribute('type', 'text/javascript'); charset && scr.setAttribute('charset', charset); scr.setAttribute('src', url); document.getElementsByTagName('head')[0].appendChild(scr); }; baidu.script._removeScriptTag = function(scr){ if (scr.clearAttributes) { scr.clearAttributes(); } else { for (var attr in scr) { if (scr.hasOwnProperty(attr)) { delete scr[attr]; } } } if(scr && scr.parentNode){ scr.parentNode.removeChild(scr); } scr = null; }; baidu.script.getscript = function (url, opt_callback, opt_options) { var scr = document.createElement("SCRIPT"), scriptLoaded = 0, options = opt_options || {}, charset = options['charset'], callback = opt_callback || function(){}, timeOut = options['timeOut'] || 0, timer; // IE和opera支持onreadystatechange // safari、chrome、opera支持onload scr.onload = scr.onreadystatechange = function () { // 避免opera下的多次调用 if (scriptLoaded) { return; } var readyState = scr.readyState; if ('undefined' == typeof readyState || readyState == "loaded" || readyState == "complete") { scriptLoaded = 1; try { callback(); clearTimeout(timer); } finally { scr.onload = scr.onreadystatechange = null; baidu.script._removeScriptTag(scr); } } }; if( timeOut ){ timer = setTimeout(function(){ scr.onload = scr.onreadystatechange = null; baidu.script._removeScriptTag(scr); options.onfailure && options.onfailure(); }, timeOut); } baidu.script._createScriptTag(scr, url, charset); };