<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>复选框的全选和取消</title> <script type="text/javascript"> function selectAll(ckname){ var ck=document.getElementsByName(ckname); for(i=0;i<ck.length;i++) ck[i].checked=true; } function unselectAll(ckname){ var ck=document.getElementsByName(ckname); for(i=0;i<ck.length;i++) ck[i].checked=false; } </script> </head> <body> <form> <input type="button" value="全选" οnclick="selectAll('interest')"> <input type="button" value="取消选择" οnclick="unselectAll('interest')"> <input type="checkbox" name="interest" value="study"/>学习 <input type="checkbox" name="interest" value="read"/>阅读 <input type="checkbox" name="interest" value="sport"/>运动 <input type="checkbox" name="interest" value="travel"/>旅行 <input type="checkbox" name="interest" value="draw"/>绘画 <input type="checkbox" name="interest" value="music"/>音乐
</form> </body> </html>