0

我希望你能帮帮我!此功能在 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";
    }
}

谁能帮我?谢谢!

4

2 回答 2

0

您需要使用currentTargetIE 的属性。检查可用的目标:

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";
    }
}
于 2012-04-24T12:21:57.423 回答
0

您需要srcElement而不是target在 IE < 9 中。您可能还需要(取决于事件处理程序的附加方式)需要window.event在 IE 中使用。

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";
    }
}
于 2012-04-24T14:11:19.443 回答