2012-04-24 105 views
0

我希望你能幫助我! 此功能在Internet Explorer中不起作用!我能怎麼做?Internet Explorer和目標事件

function docClick (oEvent) { 
    var bHide = true, oTable = document.getElementById("content_tab"); 
    for (var oItTarget = oEvent.target; oItTarget; oItTarget = oItTarget.parentNode) { 
     if (oItTarget === oTable) { bHide = false; break; } 
    } 
    if (bHide) { 
     oTable.style.visibility = "hidden"; 
    } 
} 

任何人都可以幫我嗎?謝謝!

+0

如果您還可以提及瀏覽器版本,會更好。 – 2012-04-24 15:16:35

回答

0

您需要爲IE使用currentTarget屬性。檢查什麼樣的目標是提供:

var oItTarget = oEvent.target ? oEvent.currentTarget : oEvent.target; 

或者在你的函數:

function docClick (oEvent) { 
    var bHide = true, oTable = document.getElementById("content_tab"); 
    for (var oItTarget = oEvent.target ? oEvent.currentTarget : oEvent.target; oItTarget; oItTarget = oItTarget.parentNode) { 
     if (oItTarget === oTable) { bHide = false; break; } 
    } 
    if (bHide) { 
     oTable.style.visibility = "hidden"; 
    } 
} 
+0

否。如果'target'不可用(因爲它不在IE <9中),那麼既不是'currentTarget'。 – 2012-04-24 14:08:47

0

您需要srcElement而不是target在IE < 9.您還可以(根據事件處理程序如何連接)需要在IE中使用window.event

function docClick (oEvent) { 
    oEvent = oEvent || window.event; 
    var target = oEvent.target || oEvent.srcElement; 

    var bHide = true, oTable = document.getElementById("content_tab"); 
    for (var oItTarget = target; oItTarget; oItTarget = oItTarget.parentNode) { 
     if (oItTarget === oTable) { bHide = false; break; } 
    } 
    if (bHide) { 
     oTable.style.visibility = "hidden"; 
    } 
} 
+0

非常感謝你的幫助!我明白!現在可以了 – user1353633 2012-04-24 15:05:53