javascript checkbox全選和反選的簡單實現
發現這樣寫checkbox全選和反選最簡潔明了。
1
2
3
4
5
6
|
function tempUser(val){ $( "input[name='userid']" ).each( function () { this .checked = val; }); } <br> |
1
2
3
4
5
6
7
8
|
<input type= 'checkbox' onclick= "tempUser(this.checked)" /> <input type= 'checkbox' name= "userid" /> <input type= 'checkbox' name= "userid" /> <input type= 'checkbox' name= "userid" /> <input type= 'checkbox' name= "userid" /> <input type= 'checkbox' name= "userid" /> <input type= 'checkbox' name= "userid" /> <input type= 'checkbox' name= "userid" /> |
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
原文鏈接:http://blog.csdn.net/enterys/article/details/14449763