<!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=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function()
{
    var obtn1=document.getElementById("btn1");
    var obtn2=document.getElementById("btn2");
    var obtn3=document.getElementById("btn3");
    var odiv=document.getElementById("div1");
    var ach=odiv.getElementsByTagName("input");
    obtn1.onclick=function()
    {
        for(i=0;i<ach.length;i++)
        {
            ach[i].checked=true;
        }
    }
    obtn2.onclick=function()
    {
        for(i=0;i<ach.length;i++)
        {
            ach[i].checked=false;
        }
    }
    obtn3.onclick=function()
    {
        for(i=0;i<ach.length;i++)
        {
            if(ach[i].checked==true)//注意if里面的==等号不能和赋值号=混淆
            {
                ach[i].checked=false;
            }
            else
            {
                ach[i].checked=true;
            }    
        }
    }
}
</script>
</head>

<body>
<input  id="btn1" type="button" value="全选"  /></br>
<input  id="btn2" type="button" value="不选"  /></br>
<input  id="btn3" type="button" value="反选"  /></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>
</div>
</body>
</html>
    

 

相关文章:

  • 2022-03-07
  • 2021-10-01
  • 2021-12-08
  • 2021-11-22
  • 2021-12-14
  • 2021-09-17
  • 2021-11-10
  • 2022-01-14
猜你喜欢
  • 2022-02-01
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
相关资源
相似解决方案