一直會碰見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);}});});
同樣,也是可以達到預期的效果。。。