互联网资源管理器和目标事件

时间:2012-04-24 12:16:44

标签: javascript 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";
    }
}

任何人都可以帮助我吗?谢谢!

2 个答案:

答案 0 :(得分: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";
    }
}

答案 1 :(得分:0)

在IE中,您需要srcElement而不是target< 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";
    }
}