javascript - 在javascript中查找具有相同自定义属性的元素数量

标签 javascript

我有一个包含多行的表,具有公共(public)自定义属性 prId 。我怎样才能查出没有。具有相同自定义属性的行。我不能使用jquery

<tr id="mainRow2" prId = "2"></tr>
<tr id="subRow2_1" prId = "2"></tr>
<tr id="subRow2_2" prId = "2"></tr>
<tr id="subRow2_3" prId = "2"></tr>
<tr id="mainRow5" prId = "5"></tr>
<tr id="subRow5_1" prId = "5"></tr>
<tr id="subRow5_2" prId = "5"></tr>
<tr id="subRow5_3" prId = "5"></tr>
<tr id="subRow5_4" prId = "5"></tr>

最佳答案

尝试:

document.querySelectorAll("[prId='" + 2 + "']").length

工作中:http://jsfiddle.net/rLnTD/3/

关于javascript - 在javascript中查找具有相同自定义属性的元素数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18502963/

相关文章:

javascript - 正则表达式适用于在线测试器,不适用于 Typescript Regexp

javascript - Angular 在自定义指令中设置新变量

javascript - 在python中读取二进制数据,通过restful api发送并将文件保存在nodejs中

javascript - 当我在记事本上写完我的javascript程序后,我该把它放在哪里

javascript - 处理cloudant数据库连接失败

javascript - 单击第一个复选框选择多个复选框

javascript - 在 html 中访问在单独的 JavaScript 文件中声明的变量

javascript - VB.NET 如何在 GeckoFX 中禁用 javascript 警报和 javascript 错误

javascript - 如何检查 goBack() 函数在 react 导航中是否可行?

javascript - ajax 中的实际请求类型 'HEAD' 是什么?