-3
我想在selectall复选框勾选时检查所有复选框,但在我的情况下,复选框是动态制作的。当我点击selectall复选框时,所有复选框都被选中但不是选中所有复选框,取消选中。
的JavaScript选中所有复选框未点击它时不勾选
function selectAll() {
alert("enter selectall");
$('.checkall').prop('checked', isChecked('selectall'));
}
function isChecked(checkboxId) {
alert(checkboxId);
alert("enterischecked");
var id = '#' + checkboxId;
return $(id).is(":checked");
}
function resetSelectAll() {
alert("resetselectall");
// if all checkbox are selected, check the selectall checkbox
// and viceversa
if ($(".checkall").length == $(".checkall:checked").length) {
$("#selectall").attr("checked", "checked");
} else {
$("#selectall").removeAttr("checked");
}
}
HTML代码
<body>
<table id="notificationsTableId" style="width: 1744px;">
<thead>
<tr role="row">
<th rowspan="1" colspan="1" style="width: 30px;" aria-label="">
<input type="checkbox" id="selectall" onclick="selectAll();">Select all</input>
</th>
<th tabindex="0" rowspan="1" colspan="1" style="width: 203px;">Type</th>
<th tabindex="0" rowspan="1" colspan="1" style="width: 354px;">Status</th>
</tr>
</thead>
<tbody role="alert">
<tr class="results-table-row odd">
<td align="center">
<input type="checkbox" class="checkall" name="selectedId" value="" onclick="resetSelectAll();" />
</td>
<td>Stop Noted Record</td>
<td>Closed (No investigation required)</td>
</tr>
<tr class="results-table-row even">
<td align="center">
<input type="checkbox" class="checkall" name="selectedId" value="" onclick="resetSelectAll();" />
</td>
<td>Stop Noted Record</td>
<td>Open (New)</td>
</tr>
<tr class="results-table-row even odd">
<td align="center" class=" ">
<input type="checkbox" class="checkall" name="selectedId" value="" onclick="resetSelectAll();" />
</td>
</tr>
</tbody>
</table>
注意
i am using ie8
你应该提供呈现的HTML标记,也许的jsfiddle –
@ A.Wolff我现在已经更改HTML – user2841408