mvc4
C# MVC4 How to implement select all checkbox.
$("#chkAll").click(function () { if (this.checked) { $("input[name='chkId']").each(function () { this.checked = true; }); } else { $("input[name='chkId']").each(function () { this.checked = false; }); } });
<input type="checkbox" id="chkAll" />全选 <input type="checkbox" name="chkId" value="id1" /> <input type="checkbox" name="chkId" value="id2" />
window.onload = function () { $("#chkAll").click(function () { $("input[name='chkId']").attr("checked", this.checked); }); }