Heim >Web-Frontend >HTML-Tutorial >C# MVC4 怎么实现全选checkbox。_html/css_WEB-ITnose
mvc4
C# MVC4 怎么实现全选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); }); }