JavaScript 動態加入外部.js 檔案 @ R~福氣拉! :: 隨意窩 Xuite日誌
  • BloggerAds
  • 關鍵字
  • Search Google
  • Google
    1. 沒有新回應!
  • 看起來滿像樣
  • 工商時間
  • 2009-05-20 13:31 JavaScript 動態加入外部.js 檔案
    平均分數:0 顆星    投票人數:0
    我要評分:

    JavaScript 動態加入外部.js 檔案


    var eJS=document.createElement("script");  
    document.body.insertAdjacentElement('beforeEnd',eJS);
    eJS.language="JavaScript"  
    eJS.src="../js/T.js"         

    要注意在T.js 還沒完全戴入前,是無法執行T.js 內的函數!

    ----------------------------
    dhtml語法
    oElement = object.insertAdjacentElement(sWhere, oElement)

    Parameters 參數說明

    BeforeBegin 在目前項目之前插入項目。
    AfterBegin 在目前項目之後插入項目,但要在目前項目中的所有其他內容之前。
    BeforeEnd 在目前項目之後插入項目。
    AfterEnd 在目前項目之後插入項目,但要在目前項目中的所有其他內容之後。


    sWhere Required. Stringthat specifies where to insert the HTML element, using one of the following values:
    beforeBegin Inserts oElement immediately before the object.
    afterBegin Inserts oElement after the start of the object but before all other content in the object.
    beforeEnd Inserts oElement immediately before the end of the object but after all other content in the object.
    afterEnd Inserts oElement immediately after the end of the object.
     
    oElement Required. Object that specifies the element to be inserted adjacent to the object that invoked the insertAdjacentElement method.

    ----------------------------
    相關資訊: http://blog.roodo.com/rocksaying/archives/2741057.html


    --------------------------------------------------------------IE & Chrome 適用
    var eJS=document.createElement("script");
    document.body.insertAdjacentElement('beforeEnd',eJS);
    eJS.language="JavaScript" ;
    eJS.src="../js/eMapShortPath.js";

    @@ 但Firefox 卻不能使用....找了一下..
    --------------------------------------------------------------IE & Chrome & FF 適用
    var element=document.createElement('script');
    element.setAttribute('src', '../js/eMapShortPath.js');
    document.body.appendChild(element);

    小米 / Xuite日誌 / 回應(0) / 引用(0) / 好文轉寄
    回應