搜索

实现checkbox全选

原创 2019-03-09 18:16:48 254
摘要:<!DOCTYPE html><html><head>    <title>JavaScript案例2——全选</title>    <link rel="shortctut icon" type="image/x-icon" hre

<!DOCTYPE html>
<html>
<head>
    <title>JavaScript案例2——全选</title>
    <link rel="shortctut icon" type="image/x-icon" href="img/none.ico">
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <style type="text/css">
     .box{height: 300px;width: 200px;border: 1px solid #ccc;border-radius: 5px; padding: 5px 10px; margin: 20px auto;}
    </style>

</head>
<body>
<div class="box">
    <div>
    <input type="checkbox" name="chekall" onclick="allselct();"><label for="chekall">全选</label>
    </div>
<input type="checkbox" name="item">选项1<br>
<input type="checkbox" name="item">选项2<br>
<input type="checkbox" name="item">选项3<br>
<input type="checkbox" name="item">选项4<br>
<input type="checkbox" name="item">选项5<br>
<input type="checkbox" name="item">选项6<br>
<input type="checkbox" name="item">选项7<br>
<input type="checkbox" name="item">选项8<br>
</div>
<script type="text/javascript">
    function allselct(){
        var m=document.getElementsByName("item");
        for(i=0;i<m.length;i++){
            m[i].checked=true;
                }    
    }

</script>
</body>
</html>

批改老师:韦小宝批改时间:2019-03-10 09:07:03
老师总结:写的很不错 全选这个在实际的开发中是很重要的位置 所有网站基本上都会使用到 一定要好好掌握

发布手记

热门词条