首页 > Web开发 > 详细

原生js获取页面所有的checkbox

时间:2018-07-10 17:31:46      阅读:235      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="author" content="杨欣">
    <title>获取页面所有的checkbox</title>
</head>

<body>
    <input type="checkbox" name="box1" id="box1">box1
    <input type="checkbox" name="box2" id="box2">box2
    <input type="checkbox" name="box3" id="box3">box3
    <input type="checkbox" name="box4" id="box4">box4
    <input type="checkbox" name="box5" id="box5">box5
    <input type="checkbox" name="box6" id="box6">box6
    <script>
        var inputs = document.getElementsByTagName("input");
        var boxs = [];
        for (let i = 0; i < inputs.length; i++) {
            if (inputs[i].type == "checkbox") {
                boxs.push(inputs[i])
            }
        }
       console.log(boxs)
    </script>
</body>

</html>

  

原生js获取页面所有的checkbox

原文:https://www.cnblogs.com/samsara-yx/p/9290051.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!