jQuery UI 按钮在 IE7 中不会保持隐藏状态
好的,
我制作了一个 Twitter 风格的控制面板来应用过滤器并对列表进行排序, 它的代码是这样的:
<div id="drawer">
<div id="orderDrawer" class="subDrawer" >
<div class="closeDrawer clearfix ui-icon ui-icon-closethick">close</div>
<h4>sorteer</h4>
<div id="orderPanel">
<!--some content-->
</div>
</div>
<div id="filterDrawer" class="subDrawer" >
<div class="closeDrawer clearfix ui-icon ui-icon-closethick">close</div>
<h4>Filters</h4>
<div id="filterPanel">
<!-- some content -->
</div>
<div id="filterButtonBar" class="drawerButtons">
<button id='applyFilter' name='applyFilter'>Apply</button>
</div>
</div>
</div>
这与以下 JS 代码一起工作:
$("#orderPanelButton").click( function(){
if( $(".subDrawer[id!=orderDrawer]").is(":visible") ) {
$("#drawer").slideUp( function() {
$(".subDrawer").hide();
$("#orderDrawer").show();
$("#drawer").slideDown();
});
} else {
$(".subDrawer").hide();
$("#orderDrawer").show();
$("#drawer").slideToggle();
}
});
$("#filterPanelButton").click( function(){
if( $(".subDrawer[id!=filterDrawer]").is(":visible") ) {
$("#drawer").slideUp( function() {
$(".subDrawer").hide();
$("#filterDrawer").show();
$("#drawer").slideDown();
});
} else {
$(".subDrawer").hide();
$("#filterDrawer").show();
$("#drawer").slideToggle();
}
});
最后我使用 jQuery UI 按钮来塑造按钮:
$("#applyFilter").click(function(){
$("#filterForm").submit();
});
$("[name='applyFilter']").button({icons: {
primary:'ui-icon-arrowreturnthick-1-e'}});
这在所有测试的浏览器(FF、chrome、IE8)中都效果很好,但在 IE7 中则不然。在那里,当我使用必要的隐藏和 sliderToggles 将 #drawer 的内容从“过滤器”更改为“顺序”时,会出现 applyFilter 按钮的空幽灵。当你将鼠标悬停在它上面时,它就会消失。
这里有人知道为什么会发生这种情况以及如何摆脱 IE7 代码中这个恼人的小错误吗?
[2010 年 7 月 22 日更新] 我找到了一个临时解决方案,但希望找到更简洁的东西。 我添加了以下 JS,基于 PHP 的 MSIE 7.0 检测:
$(".subDrawer[id!=' . $drawer . 'Drawer]").find("button").each(function(){
$(this).css("display","none");
});
$(".subDrawer[id=' . $drawer . 'Drawer]").find("button").each(function(){
$(this).css("display","");
});
其中 $drawer = subDrawer ID 的第一部分(过滤器/订单)。
Ok,
I have made a twitter-style control panel to apply filters and sorting to a list,
the code for it is like this:
<div id="drawer">
<div id="orderDrawer" class="subDrawer" >
<div class="closeDrawer clearfix ui-icon ui-icon-closethick">close</div>
<h4>sorteer</h4>
<div id="orderPanel">
<!--some content-->
</div>
</div>
<div id="filterDrawer" class="subDrawer" >
<div class="closeDrawer clearfix ui-icon ui-icon-closethick">close</div>
<h4>Filters</h4>
<div id="filterPanel">
<!-- some content -->
</div>
<div id="filterButtonBar" class="drawerButtons">
<button id='applyFilter' name='applyFilter'>Apply</button>
</div>
</div>
</div>
This works together with the following JS code:
$("#orderPanelButton").click( function(){
if( $(".subDrawer[id!=orderDrawer]").is(":visible") ) {
$("#drawer").slideUp( function() {
$(".subDrawer").hide();
$("#orderDrawer").show();
$("#drawer").slideDown();
});
} else {
$(".subDrawer").hide();
$("#orderDrawer").show();
$("#drawer").slideToggle();
}
});
$("#filterPanelButton").click( function(){
if( $(".subDrawer[id!=filterDrawer]").is(":visible") ) {
$("#drawer").slideUp( function() {
$(".subDrawer").hide();
$("#filterDrawer").show();
$("#drawer").slideDown();
});
} else {
$(".subDrawer").hide();
$("#filterDrawer").show();
$("#drawer").slideToggle();
}
});
and finally I use jQuery UI button to shape the button:
$("#applyFilter").click(function(){
$("#filterForm").submit();
});
$("[name='applyFilter']").button({icons: {
primary:'ui-icon-arrowreturnthick-1-e'}});
This works great in all tested browsers (FF, chrome, IE8), but not in IE7. There, when I change the content of #drawer from 'filter' to 'order' with the necessary hides and slideToggles an empty ghost of the applyFilter button appears. A ghost that will disappear when you hover over it.
Anybody here got any idea why this happens and how I can get rid of this annoying little bug in my code for IE7?
[update 22/Jul/10]
I have found a temporarily solution but hope to find something a little more neat.
I added the following JS, based on MSIE 7.0 detection by PHP:
$(".subDrawer[id!=' . $drawer . 'Drawer]").find("button").each(function(){
$(this).css("display","none");
});
$(".subDrawer[id=' . $drawer . 'Drawer]").find("button").each(function(){
$(this).css("display","");
});
Where $drawer = the first part of the subDrawer ID (filter / order ).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经稍微了解了原因部分,这里将对此进行讨论:
为什么 jQuery 显示/隐藏使用 display:none 而不是可见性:隐藏?
我还认为部分“原因”是由于 IE7 非标准 CSS 实现/解释(又名错误)。
我相信这里概述了修复方法:
使用 jQuery 时 Internet Explorer 7 中的淡入淡出问题
http://jquery-howto。 blogspot.com/2009/02/font-cleartype-problems-with-fadein-and.html
You've already hit on the why part a bit, which is discussed here:
Why does jQuery show/hide use display:none instead of visibility:hidden?
I also think part of the "why" is due to an IE7 non-standard CSS implementation/interpretation (aka bug).
I believe the fix is outlined here:
Fading issues in Internet Explorer 7 when using jQuery
and
http://jquery-howto.blogspot.com/2009/02/font-cleartype-problems-with-fadein-and.html