全选

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>全选 </title>
</head>

<body>
<script>
    document.write("<ul>");
        for(var i=0;i<10;i++){
            document.write("<li>");
            document.write('<input type="checkbox" name="ids[]" value="'+i+'">aaaaa');
            document.write("</li>")
            }
    document.write("</ul>")

</script>
    <label for="aa">
    <input type="checkbox" onClick="sall(this)"></label>
        全选
    </label>
    <script>
        var names=document.getElementsByName("ids[]");
        function sall(obj){
            for(var i=0;i<names.length;i++){
                    names[i].checked=obj.checked;
            }
        }
    </script>
</body>
</html>

 

posted @ 2016-11-23 12:42  Jinsuo  阅读(168)  评论(0编辑  收藏  举报