如何使用属性 display:none 测量类的长度
How to measure the length of a class with the property display:none
有没有办法用javaScript jQuery中具有display:none的某个类来测量元素?
例如:
<div class="x" style="display: none;"></div>
<div class="x" style="display: none;"></div>
<div class="x"></div>
如果我在下面执行此代码,我将收到警报"3",因为有 3 个元素带有 class="x"。
var n = document.getElementsByClassName('x').length;
alert(n);
正确的选择器是什么,以便我的警报显示只有 2 个类"x"并显示:无?
感谢您的帮助!
尝试混合类名和 :hidden 选择器。
var list = $('.x:hidden'); //select all elements with class x and are hidden.
演示
在香草JS中:
var n = document.getElementsByClassName('x'); //get the elements with class
var nodeList = [];
for(var i=0, len = n.length; i<len; i++){ //loop through them
if(n[i].style.display === "none") nodeList.push(n[i]); //check for display property value and push the element to the list.
}
alert(nodeList.length); //You have the list of elements with desired properties.
小提琴
相关文章:
- 如果连接类型为none,则Javascript Function Only警报
- 列表样式在IE中未设置为none,但在IE中适用
- Potree/Three.js测量问题
- 重写CSS:使用jquery显示none属性
- 如何解析和捕获任何测量单位
- Regex用于手上测量
- 测量输入时间
- 如何在使用jQuery应用display:none后正确显示元素
- 在javascript中将样式显示从none更改为block
- 有没有更好的方法可以测量从Ajax调用返回数据所需的总时间
- Javascript -> CSS (display:none to display:block)
- 在Chrome开发工具中测量步骤之间的时间
- 当display:none时,getElementById()无法获取元素
- 正在测量全局命名空间的污染
- Greasemonkey:当style=“display: none;”发生变化时如何做某事
- 测量渲染时间
- 在javascript中测量websockets数据输入/输出的大小
- jQuery Transit:Object none 没有方法 'setFromString'
- Pre 标记似乎忽略了样式属性(例如 display:none)
- 如何使用属性 display:none 测量类的长度