IE 不支持 jQuery .show()

发布于 2024-08-04 14:42:09 字数 783 浏览 3 评论 0原文

我构建了一些简单的选项卡,单击这些选项卡会显示隐藏的 div。很简单。除了 IE 之外,一切都运行良好。由于某种原因,即使我使用 jQuery .show() 函数,它也不会将隐藏的 div 设置为 display:block,而只是将其隐藏,这非常令人沮丧。

示例页面:http://www.puc.edu/alumni/give-puc

jQuery for tabs:

$('#teamTabs li').click(function() {
 $('#teamTabs li').removeClass('selected');
 $(this).addClass('selected');
 $('.teamTab').hide();
 var id = $(this).attr('id');
 if (id == 'teamTab1') {
  $('#team1').show();
 } else if (id == 'teamTab2') {
  $('#team2').show();
 } else if (id == 'teamTab3') {
  $('#team3').show();
 } else if (id == 'teamTab4') {
  $('#team4').show();
 }//end else if

 return false;

});//end click

有什么想法为什么 IE 不会将 div 设置为 display:block 吗?

I built some simple tabs, which when clicked, show a hidden div. Very simple. All works well, except in IE. For some reason, even though I am using the jQuery .show() function, it won't set the hidden div to display:block, but just leaves it hidden, and it is very frustrating.

Example Page: http://www.puc.edu/alumni/give-puc

jQuery for tabs:

$('#teamTabs li').click(function() {
 $('#teamTabs li').removeClass('selected');
 $(this).addClass('selected');
 $('.teamTab').hide();
 var id = $(this).attr('id');
 if (id == 'teamTab1') {
  $('#team1').show();
 } else if (id == 'teamTab2') {
  $('#team2').show();
 } else if (id == 'teamTab3') {
  $('#team3').show();
 } else if (id == 'teamTab4') {
  $('#team4').show();
 }//end else if

 return false;

});//end click

Any ideas why IE wouldn't set the div to display:block?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧故 2024-08-11 14:42:09

我意识到您已经发现问题出在其他地方,但对于其他人后来发现这个问题(并将其从无答案列表中删除),您可以大大减少/简化您的代码:

$('#teamTabs li').click(function() {
  $(this).addClass('selected').siblings().removeClass('selected');
  $('.teamTab').hide();
  $('#team'+ this.id.replace('teamTab','')).show();
  return false;
});

I realize you've already figured out the problem was elsewhere, but for others finding this later (and to get this off the no answers list), you can slim down/simplify your code quite a bit:

$('#teamTabs li').click(function() {
  $(this).addClass('selected').siblings().removeClass('selected');
  $('.teamTab').hide();
  $('#team'+ this.id.replace('teamTab','')).show();
  return false;
});
南城旧梦 2024-08-11 14:42:09

我有类似的问题。我发现 IE 实际上正在将显示更改为块,但它也使每个 display:none; 块具有 visibility:hidden;

我能够让我的元素正确显示通过执行以下操作:

$('#team1').show(); // shows for all browsers but IE
if($.browser.msie){
   $('#team1').css({"visibility":"visible"});
}

在将问题范围缩小到两个可能隐藏 HTML 的 CSS 元素后,我通过使用两个警报发现了这一点:display:none;和可见性:隐藏。

保证如果您在 $('#team1').show(); 之后立即执行此警报

alert( $('#team1').css("display"));< /code> 您的显示将被阻止并且
警报($('#team1').css(“可见性”));您的可见性将被隐藏。

似乎 IE 会自动隐藏块,当它们在 css 中设置为“none”显示,然后通过 Jquery 更改时。对于定义为 display:block; 的元素来说,这似乎不是问题。只要您首先在 CSS 中定义这些元素,就应该始终没问题。

希望这可以帮助其他遇到此问题的人:)

I had a similar issue. I found that IE actually was changing display to block, but it also made each display:none; block have visibility:hidden;

I was able to get my elements to show correctly by doing the following:

$('#team1').show(); // shows for all browsers but IE
if($.browser.msie){
   $('#team1').css({"visibility":"visible"});
}

I found this by using two alerts after narrowing down my issue to the two possible CSS elements that could hide my HTML: display:none; and visibility:hidden.

Guaranteed that if you do this alert right after $('#team1').show();

alert( $('#team1').css("display")); your display will be block and
alert( $('#team1').css("visibility")); your visibility will be hidden.

Seems like IE automatically hides blocks when they are set to a display of "none" in the css and then changed via Jquery. It also seems as though this isn't an issue for elements that are defined as display:block; These elements should always be ok as long as you defined them first in the CSS.

Hope this helps anyone else out there having this issue :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文