一直会碰见input 全选框的问题,先整理一种情况:
1.
<input id="selectAll" type="checkbox" />全选
2.
<input type='checkbox' id='id1' name='cb' value='1' />value1 <input type='checkbox' id='id2' name='cb' value='2' />value2 <input type='checkbox' id='id3' name='cb' value='3' />value3
3.
//全选框 jQuery(function () { jQuery("#selectAll").click(function () { //全选 if (this.checked) { jQuery("input[name='cb']").each(function () { this.checked = true; }); } else { //取消全选 jQuery("input[name='cb']").each(function () { this.checked = false; }); } } ); });
4.或者另外一种很简便的方法:
//全选框 jQuery(function () { jQuery("#selectAll").click(function () { //全选 jQuery("input[name='cb']").attr("checked", true); } else { //取消全选 jQuery("input[name='cb']").attr("checked", true); } } ); });
同样,也是可以达到预期的效果。。。