假设有以下三个元素
<div id="tab01">tab01</div>
<div id="tab02" style="display: none;">tab02</div>
<div id="tab03" style="display: none;">tab03</div>
如何使用jQuery选择没有内联样式display: none
的元素?
由于
答案 0 :(得分:6)
您可以使用:hidden
选择隐藏的元素,使用:visible
...
$('div:visible');
...但是如果您特别需要没有将display; none
设置为内联样式的元素,请尝试此操作...
$('div').filter(function() {
return $(this).attr('style') == undefined || $(this).attr('style').indexOf('display: none;') == -1
}).
...当然,如果你依赖于此,你应该重新考虑你的问题。
答案 1 :(得分:0)
我有一个类似的问题,发现这个有用的帖子。上面的答案已经足够,但我想在不使用indexOf方法的情况下这样做,因为它对我来说似乎并不直观。
这是我想出的以及相关的垃圾箱。我在上面留下了上面的答案代码,表明它们都有效。希望这有助于作为替代方法。 http://jsbin.com/coroxa/1/edit?html,js,output
$('.bottom-drawer').filter(function() {
//return $(this).attr('style').indexOf('display: block;') === 0;
return $(this).is("[style*='display: block']") === true;
}).slideToggle(620);