全选 取消 反选

<html>
<head>
<meta charset="utf-8">
<title>全选/反选/取消</title>

<script type="text/javascript">
function xuan(type) {
var qcheck=document.getElementsByName("check[]");
if(type=="quanxuan"){
for(var i=0;i<=qcheck.length;i++){
qcheck[i].checked=true;
}
}

if(type=="quxiao"){
for(var i=0;i<=qcheck.length;i++){
qcheck[i].checked=false;
}
}

if(type=="fanxuan"){
for(var i=0;i<=qcheck.length;i++){
if(qcheck[i].checked){
qcheck[i].checked=false;
}
else{
qcheck[i].checked=true;

}
}
}
}

</script>

</head>

<body>

<p>全选
<input name="myCheck1" type="checkbox" onClick="xuan('quanxuan')" id="quanxuan">
取消
<input name="myCheck2" type="checkbox" onClick="xuan('quxiao')" id="quxiao">
反选
<input name="myCheck3" type="checkbox" onClick="xuan('fanxuan')" id="fanxuan">
</p>
<p>
1<input name="check[]" type="checkbox" onclick='add()'>
2<input name="check[]" type="checkbox" onclick='add()'>
3<input name="check[]" type="checkbox" onclick='add()'>
4<input name="check[]" type="checkbox" onclick='add()'>
5<input name="check[]" type="checkbox" onclick='add()'></p>

</body>
</html>

posted on 2014-08-22 17:10  moliwanzi  阅读(151)  评论(0编辑  收藏  举报

导航