function loadjs( 🎜>
var head = $('head').remove('#loadscript');
$("
" "" "ipt>").attr({src:file,type:'text/javascript',id:'load'}).appendto(head );
}
以下程式碼是摘自news.qq.com頁面裡的程式碼的,本人未進行測試,程式看著應該沒有問題的,可以做為參考的,主要用來在網頁底部位置,實現動態載入js文件到網頁標籤的後面,透過DOM來實現的,程式碼如下:
<script><script>< SCRIPT_TIMEOUT = 20000;<BR>var QVPL_PATH = "/QVPL1.0.0.js";<BR>
<BR>function loadHelper (jsurl) {var oScriptEl, oTimeoutHDL, oHead;<P>oScriptEl = document.createElement("script");<BR>oScriptEl.type = "text/javascript";<BR>oScriptScriptEl. .language = "javascript";<BR>oScriptEl.src = jsurl;<BR>oScriptEl.onreadystatechange = doCallback;<BR>
<BR>oScriptEl.onload = function(){<P>this.readyState = "complete";<BR>doCallback();<BR>if(typeof(lianbo) == "object"){<BR>lianbo.init(window.QVPL);<BR>}<BR>};<BR>
<BR>oTimeoutHDL = window.setTimeout(doError,SCRIPT_TIMEOUT);document.getElementsByTagName("head")[0].appendChild(oScriptEl);<P>
<BR>function doCallback(){<P>if (oScriptEl.readyState == "complete" || oScriptEl.readyState == "loaded")<BR>{<BR>oScriptEl.onload = oScriptEl.onstatey== new Function();<BR>window.clearTimeout(oTimeoutHDL);<BR>}<BR>};<BR>
<BR>function doError(){<P>oScriptEl.parentNode.removeChild(oScriptEl);<BR>};<BR>}<BR>
<BR>loadHelper(QVPL_PATH);</script>