在我的 Rails 应用程序中,在表单中,我有几个文本区域。属性 display:none
是为某些文本区域指定的。如何使用 JQuery 获取具有 display:none
属性的文本区域的计数。
最佳答案
您可以使用:hidden
选择器:
var hiddenCount = $('textarea:hidden').length;
Additional Notes:
Because :hidden is a jQuery extension and not part of the CSS specification, queries using :hidden cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. To achieve the best performance when using :hidden to select elements, first select the elements using a pure CSS selector, then use .filter(":hidden").
因此,为了获得最佳性能:
var hiddenCount = $('textarea').filter(':hidden').length;
关于jquery - 使用 Jquery 查找具有特定属性的文本区域的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16912917/