我有一个像这样的复选框 我需要通过使用class" levelTwo"来检查复选框的数量。和data-parent-id = 2
在这里预期的结果是3 因为使用data-parent-id = 2和class =" levelTwo"
检查了三个复选框<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="2" checked>
<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="2">
<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="2" checked>
<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="2" checked>
<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="3">
<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="4">
<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="4">
答案 0 :(得分:1)
描述:选择具有指定属性的元素,其值完全等于某个值。
console.log($(":checkbox.levelTwo:checked[data-parent-id=2]").length)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="2" checked>
<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="2">
<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="2" checked>
<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="2" checked>
<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="3">
<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="4">
<input type="checkbox" class="userPerm levelTwo" data-permid="10" data-userid="25" data-parent-id="4">