表单全选,不选和反选

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload=function()
{
var oBtn1=document.getElementById("btn1");
var oBtn2=document.getElementById("btn2");
var oBtn3=document.getElementById("btn3");

var oDiv=document.getElementById("div1");
var oCh=oDiv.getElementsByTagName("input");
oBtn1.onclick=function()
{
for(var i=0;i<oCh.length;i++)
{
oCh[i].checked=true;
}

}

oBtn2.onclick=function()
{
for(var i=0;i<oCh.length;i++)
{
oCh[i].checked=false;
}

}


oBtn3.onclick=function()
{
for(var i=0;i<oCh.length;i++)
{
if(oCh[i].checked)
{
oCh[i].checked=false;
}
else{
oCh[i].checked=true;;
}
}

}


}

</script>

</head>

<body>

<input type="button" value="全选" id="btn1" />
<input type="button" value="不选" id="btn2" />
<input type="button" value="反选" id="btn3" /><br/>


<div id="div1">
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
<input type="checkbox" /><br/>
</div>

</body>
</html>

posted @ 2016-01-31 15:57  天--安静  阅读(290)  评论(0编辑  收藏  举报