js全选和反选

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <link rel="stylesheet" href="css/all.css" />
    </head>
    <body>
        <label for="all">全选</label>
        <input type="radio" name="check" id="all" value="" onclick="chec();"/>
        <label for="only">反选</label>
        <input type="radio" name="check" id="only"value="" onclick="nochec();"/><br />
        <input type="checkbox" name="" id="" value="" />
        <input type="checkbox" name="" id="" value="" />//可复制多个
    </body>
    <script type="text/javascript">javascript

//全选和反选在点击时让其checked为true
    var inp = document.getElementsByTagName("input");
        function chec(){//全选状态
            for(var i =2;i < inp.length;i++){                
                inp[i].checked = true;
            }
        }
        function nochec(){//反选
            for(var i =2;i < inp.length;i++){                
                inp[i].checked = false;
            }
        }
    </script>
</html>
 css

相关文章
相关标签/搜索