<script type="text/javascript">
function getAll(){
var a=document.getElementsByName("hobby");
for(var i=0;i<a.length;i++){
a[i].checked=true;
}
}
function getOut(){
var a=document.getElementsByName("hobby");
for(var i=0;i<a.length;i++){
a[i].checked=false;
}
}
function getInput(){
var a=document.getElementsByName("hobby");
for(var i=0;i<a.length;i++){
a[i].checked=!a[i].checked;
}
}
</script>
</head>
<body>
<h1>请选择你的爱好:</h1>
<input type="checkbox" name="hobby" value="football"/>足球
<input type="checkbox" name="hobby" value="basketball" />篮球
<input type="checkbox" name="hobby" value="swim" />游泳
<input type="checkbox" name="hobby" value="singing"/>唱歌<br/>
<input type="button" value="获取" onclick="getAll()"/>
<input type="button" value="全不选" onclick="getOut()"/>
<input type="button" value="反选" onclick="getInput()"/>
</body>