JS全选的操作

<!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 type="text/javascript">
    function fun1(o)
    {
        arr=document.getElementsByName("chk");
        for(var i=0;i<arr.length;i++)
        {
            arr[i].checked=o.checked;
        }
    }
    function fun2()
    {
        arr=document.getElementsByName("chk");
        for(var i=0;i<arr.length;i++)
        {
            if(arr[i].checked==false)
            {
                document.getElementById("qx").checked=false;
                return;
            }
        }
        document.getElementById("qx").checked=true;
    }

</script>


</head>
<form>    
    <input id="qx" type="checkbox"  onclick="fun1(this)"/>全选
    <input type="checkbox" name="chk" onclick="fun2()"/>语文
    <input type="checkbox" name="chk" onclick="fun2()"/>数学
    <input type="checkbox" name="chk" onclick="fun2()"/>英语
    <input type="checkbox" name="chk" onclick="fun2()"/>生物
    <input type="checkbox" name="chk" onclick="fun2()"/>物理
    <input type="checkbox" name="chk" onclick="fun2()"/>化学
</form>
<body>
</body>
</html>
原文地址:https://www.cnblogs.com/xiaoqisfzh/p/4736048.html