js 實現復選框全選 全部選
阿新 • • 發佈:2017-11-01
tails elements 全選 str byname false public xhtml under
http://blog.csdn.net/sunwei3160/article/details/38515187
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>js點擊checkbox實現全選效果</title> <script type="text/javascript"> functionDoCheck() { var ch = document.getElementsByName("choose"); if (document.getElementsByName("allChecked")[0].checked == true) { for (var i = 0; i < ch.length; i++) { ch[i].checked = true; } } else { for (var i = 0; i < ch.length; i++) { ch[i].checked= false; } } } </script> </head> <body> 請選擇愛好: <br /> <input type="checkbox" name="choose">跳舞 <input type="checkbox" name="choose">跳水 <input type="checkbox" name="choose" />跳棋 <input type="checkbox" name="choose" />跑步 <br /> <input type="checkbox" name="allChecked" id="allChecked" onclick="DoCheck()" />全選/取消 </body> </html>
js 實現復選框全選 全部選