<html>
<head>
<meta charset="utf-8"/>
<title></title>
<script type="text/javascript">
window.onload=function(){
// 全选/全不选
var chk1=document.getElementById("chk1");
// 反选
var chk2=document.getElementById("chk2");
// 获取所有的input标签
var oDiv=document.getElementById("chk");
var chks=oDiv.getElementsByTagName("input");
chk1.onclick=function(){
//alert("哈哈");
for(var i=0;i<chks.length;i++){
chks[i].checked=chk1.checked; ?// 全部选中 或全部选中
}
};
chk2.onclick=function(){
for(var i=0;i<chks.length;i++){
chks[i].checked=!chks[i].checked;// 反选
}
};
};
</script>
</head>
<body>
<div id="top">
</div><div id="container"> ???<input type="checkBox" id="chk1">全选/全不选 ???<input type="checkBox" id="chk2">反选 ???<hr size="5" color="white"> ???<div id="chk"> ???????<input type="checkBox">篮球 ???????<br> ???????<input type="checkBox">羽毛球 ???????<br> ???????<input type="checkBox">乒乓球 ???????<br> ???????<input type="checkBox">足球 ???????<br> ???????<input type="checkBox">橄榄球 ???????<br> ???????<input type="checkBox">棒球 ???</div></div>
</body>
</html>
利用js实现全、反选、全不选功能(check)
原文地址:http://blog.51cto.com/11871779/2069356