ASPX:
<input id="checkAll" name="checkAll" type="checkbox" checked="checked" onclick="ToggleCheckAll(this,'chkItem');"/>全选
<asp:Repeater ID="rptCartList" runat="server" OnItemCommand="rptCartList_ItemCommand">
<ItemTemplate>
<asp:CheckBox ID="chkItem" runat="server" Checked="true" onclick="ToggleCheckSelf('checkAll', 'chkItem')" />
</ItemTemplate>
</asp:Repeater>
原生JS:
//====功能:复选框全选、取消=====//
function ToggleCheckAll(e,item) {
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == "checkbox" && !inputs[i].disabled && (inputs[i].id.indexOf(item) > 0))
inputs[i].checked = e.checked;
}
}
//=====“全部”复选框是否选中处理(checkAll:id,chkItem:item)======//
function ToggleCheckSelf(id, item) {
var IsCheck = ($("input[id*=" + item + "]:enabled").length == $("input[id*=" + item + "]:checked").length);
$("input[id*=" + id + "]").attr("checked", IsCheck);
}
压缩版:
/*FileName:功能:复选框全选、取消 CreateTime:2017-8-29 17:43:05)
<input id="checkAll" name="checkAll" type="checkbox" checked="checked" onclick="ToggleCheckAll(this,'chkItem');"/>全选*/
function ToggleCheckAll(e, item) { var inputs = document.getElementsByTagName('input'); for (var i = 0; i < inputs.length; i++) { if (inputs[i].type == "checkbox" && !inputs[i].disabled && (inputs[i].id.indexOf(item) > 0)) inputs[i].checked = e.checked } }
/*FileName:“全部”复选框是否选中处理(checkAll:id,chkItem:item) CreateTime:2017-8-29 17:43:33
<asp:CheckBox ID="chkItem" runat="server" Checked="true" onclick="ToggleCheckSelf('checkAll', 'chkItem')" />*/
function ToggleCheckSelf(id, item) { var IsCheck = ($("input[id*=" + item + "]:enabled").length == $("input[id*=" + item + "]:checked").length); $("input[id*=" + id + "]").attr("checked", IsCheck) }