<head>
<meta charset="utf-8"/>
<script type="text/javascript">
window.onload=function(){
document.getElementById("unall").onclick=function(){
var hobbys= document.getElementsByName("hobby");
for(var i=0;i<hobbys.length;i++){
hobbys[i].checked=! hobbys[i].checked;
}
}
}
</script>
</head>
<body>
全选:<input type="checkbox" id="all"/>
反选:<input type="checkbox" id="unall"/><br>
1<input type="checkbox" name="hobby" value="1" /><br>
2<input type="checkbox" name="hobby" value="2"/><br>
3<input type="checkbox" name="hobby" value="3"/><br>
</body>
</html>