js实现js实现(全选)多选按钮的方法【附实例】(全选)多选按钮的方法【附实例】
<html> <head> <title>复选框checked属性</title> <script language="JavaScript" type="text/javascript"> function changeState(isChecked) { var chk_list=document.getElementsByTagName("input"); for(var i=0;i<chk_list.length;i++) { if(chk_list[i].type=="checkbox") { chk_list[i].checked=isChecked; } } } </script> </head> <body> <h1>请选择你的爱好</h1> <form name="myForm1"> <input type="checkbox" name="cb1" checked>看书<br> <input type="checkbox" name="cb2" checked>上网<br> <input type="checkbox" name="cb3">游戏<br> </form> <hr> <form name="myForm2"> <input type="checkbox" name="cb" onclick="changeState(this.checked)">全选 </form> </body> </html>