PrototypeJS:选择可见元素 [英] PrototypeJS: Selecting visible elements
问题描述
我试图制定一个选择器来选择一组可见元素。我们的应用程序使用的是Prototype JavaScript框架1.6.0.3版。
I am trying to formulate a selector to select a set of visible elements. Our application uses the Prototype JavaScript framework, version 1.6.0.3.
我使用的标记如下:
<ul>
<li style="display:none;">1 Hidden</li>
<li style="display:none;">2 Hidden</li>
<li style="">3 Visible</li>
<li style="display:none;">4 Hidden</li>
<li style="display:none;">5 Hidden</li>
<li style="display:none;">6 Hidden</li>
<li>7 Visible</li>
<li style="">8 Visible</li>
</ul>
如您所见,一些元素可能有一个样式属性,只有隐藏的包含字符串display:none;。我需要选择可见的< li>
元素,其中的可见性定义为不包含display:none。
As you can see, some elements may have a style attribute, but only the hidden ones contain the string "display:none;". I need to select the <li>
elements that are visible, where visibility is defined as "does not contain display:none".
我尝试了很多:
var visibleItems = $$('li[style*="display:none"]'); // Yields: [ ]
var visibleItems = $$('li[style*="display"]'); // Yields: [li, li, li, li, li], but isn't specific enough
想法?理想情况下,我希望尽可能的紧凑,但我会采取我能得到的。
Ideas? Ideally I'd like this to be as compact as possible, but I'll take what I can get.
是的,我知道 jQuery可以做到这一点,但我不想在这个应用程序中引入另一个框架,因为它大部分已经依赖于Prototype。 / p>
Yes, I know that jQuery can do this but I do not want to introduce another framework in to this application since much of it already depends on Prototype.
推荐答案
您可以使用 findAll function:
You can filter the items using the findAll function:
var notVisible = $$('li').findAll(function(el) { return !el.visible(); });
这篇关于PrototypeJS:选择可见元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!