<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
ul{
list-style: none;
}
</style>
</head>
<body>
<ul>
<li><input type="checkbox" name="basketball">篮球</li>
<li><input type="checkbox" name="basketball">足球</li>
<li><input type="checkbox" name="basketball">排球</li>
<li><input type="checkbox" name="basketball">网球</li>
<li><input type="checkbox" name="basketball" id="checkAll">全选</li>
<li><button type="button">反选</button></li>
</ul>
<script type="text/javascript">
var aInp = document.getElementsByTagName('input');
var oBtn = document.getElementsByTagName('button')[0];
var checkAll = document.getElementById("checkAll");
checkOrCancelAll.checked = function() {
for (var i = 0; i < aInp.length; i++) {
aInp[i].checked = true;
}
}
oBtn.onclick = function(){
for(var i = 0;i<aInp.length;i++){
aInp[i].checked = !aInp[i].checked;
}
}
</script>
</body>
</html>
网友评论