IE 不支持 jQuery .show()
我构建了一些简单的选项卡,单击这些选项卡会显示隐藏的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我意识到您已经发现问题出在其他地方,但对于其他人后来发现这个问题(并将其从无答案列表中删除),您可以大大减少/简化您的代码:
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:
我有类似的问题。我发现 IE 实际上正在将显示更改为块,但它也使每个
display:none;
块具有visibility:hidden;
我能够让我的元素正确显示通过执行以下操作:
在将问题范围缩小到两个可能隐藏 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 havevisibility:hidden;
I was able to get my elements to show correctly by doing the following:
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 andalert( $('#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 :)