如何选择具有特定内联样式的元素? [英] How can I select an element with a specific inline style?
本文介绍了如何选择具有特定内联样式的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设有以下三个元素
<div id="tab01">tab01</div>
<div id="tab02" style="display: none;">tab02</div>
<div id="tab03" style="display: none;">tab03</div>
如何使用jQuery选择没有内联样式display: none
的元素?
How can I use jQuery to select an element that don't have an inline style display: none
?
谢谢
推荐答案
您可以使用:hidden
选择隐藏的元素,并使用:visible
...选择可见的元素...
You can select hidden elements with :hidden
, and visible elements with :visible
...
$('div:visible');
jsFiddle .
...但是如果您特别需要没有将display; none
设置为嵌入式样式的元素,请尝试此操作...
...but if you specifically need elements which don't have display; none
set as an inline style, try this...
$('div').filter(function() {
return $(this).attr('style') == undefined || $(this).attr('style').indexOf('display: none;') == -1
}).
jsFiddle .
...当然,如果您依赖于此,则应该重新考虑您的问题.
...of course, if you are relying on this, you should rethink your problem.
这篇关于如何选择具有特定内联样式的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文