为什么jquery隐藏在IE7中无法正常工作?

时间:2011-01-28 10:19:19

标签: jquery hide show-hide internet-explorer-7

我有一个包含不同div体的弹出窗口,其中一个按下按钮显示。 以下功能适用于IE7:

function openPopup(popupDiv){
    //The popup is a div with id name popupDiv
    //It contains several bodies such as
    //alertPopupDiv, uploadPopupDiv, removePopupDiv
    //The div id name of the body to show is passed to the function

    //First hide all the bodies
    $("#popupDiv div[id$=PopupDiv]").each(function (i)
     {this.style.visibility='hidden';});  

    //Now show the relevant div
    var div = document.getElementById(popupDiv);
    if(div != null)
      {div.style.visibility = 'visible';}

   //Now call the function to load the popup itself          
   loadPopup();
}

但理想情况下,我希望使用更简单的方法:

function openPopup(popupDiv){
    $("div[id$=PopupDiv]").hide();  

    $(popupDiv).show();

   loadPopup();
}

在Firefox和IE8中哪个好,但在IE7中不起作用(它第一次被调用时有效,但如果函数是调用打开带有新容器的弹出窗口,则无法正常呈现。

1 个答案:

答案 0 :(得分:2)

使用内联或无属性

 $("#popupDiv div[id$=PopupDiv]").each(function (i)
         {this.style.display='none';});  

        //Now show the relevant div
        var div = document.getElementById(popupDiv);
        if(div != null)
          {div.style.display= 'inline';}