zoukankan      html  css  js  c++  java
  • js获取页面所有checkbox,全选,取消全选

    <!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>

     全选,取消全选

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <div>
            新闻<input type="checkbox"/><br/>
            电影<input type="checkbox"/><br/>
            音乐<input type="checkbox"/><br/>
            娱乐<input type="checkbox"/><br/>
            八卦<input type="checkbox"/><br/>
            直播<input type="checkbox"/><br/>
        </div>
        <input type="checkbox" onclick="selectAll(this);" />全选/全取消<br/>
       <script src="http://www.jq22.com/jquery/jquery-2.1.1.js"></script>
        <script type="text/javascript">
            function selectAll(checkbox) {
                $('input[type=checkbox]').prop('checked', $(checkbox).prop('checked'));
            }
        </script>
    </body>
    </html>
  • 相关阅读:
    sql分页存储过程疑惑:Row_Number与临时表哪个好?
    SQL之剪切
    在sqlserver2005中安装sql server 2000的示例数据库northwind
    安装SQL2005示例数据库
    Firefox浏览器中,Flex的FileReference上传文件,引发IOError
    Java获取方法的调用者
    ABAP screen常见语法
    XPO永久删除记录方法
    XPO的UpCasting
    在ASP.NET项目中使用XPO的最佳准则
  • 原文地址:https://www.cnblogs.com/quitpoison/p/10795603.html
Copyright © 2011-2022 走看看