你好,我有一张桌子,如下所示
function checkAll2(rowClass, status) {
var dynamicClass = $('.' + rowClass);
// alert($('.1').find(":checkbox").length);
alert($('input:checkbox.1').length);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="table1">
<tr>
<td>1a:</td>
<td><input type="checkbox" name="selected" value="1a" class="1"></td>
</tr>
<tr>
<td>1b:
</td>
<td><input type="checkbox" name="selected" value="1b" class="1"></td>
</tr>
</table>
Select All/None above<input type="checkbox" onclick="checkAll2(1,this.checked)" />
但是我需要的是我也想在不同的类中重用它,因此我将传递rowClass
,以便在我的input:checkbox
后面附加rowClass
并给我计数或该类的控件列表
答案 0 :(得分:1)
您应该以这种方式获得.1
类的数量,以使其“动态”
function checkAll2(rowClass, status) {
var dynamicClass = $('.' + rowClass);
console.log($('input:checkbox.'+rowClass).length);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<table id="table1">
<tr>
<td>1a:</td>
<td><input type="checkbox" name="selected" value="1a" class="1"></td>
</tr>
<tr>
<td>1b:
</td>
<td><input type="checkbox" name="selected" value="1b" class="1"></td>
</tr>
</table>
Select All/None above<input type="checkbox" onclick="checkAll2(1,this.checked)" />