jquery - 使用 Jquery 查找具有特定属性的文本区域的数量

标签 jquery ruby-on-rails count textarea

在我的 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/

相关文章:

mysql - 使用 mysql 的 COUNT 防止重复

javascript - 如何根据其他组件的事件更新组件 URL

ruby-on-rails - 从数组中提取名称并在每个名称后添加换行符

ruby-on-rails - 点击 Google Contacts API 时出现 "connection reset by peer"错误

html - 居中导航栏图标文本 - 使用 Bootstrap 的 Rails 应用程序

ios - NSMutableArray 不添加对象

c# - 返回列表中的最大重复项

javascript - 托管 Yui、Google map 、JQuery - 一种监控网站使用情况的简单方法?

javascript - jQuery 验证 - 多组

javascript - 如何使用 Javascript 检查文本框并重定向到 URL?