zoukankan      html  css  js  c++  java
  • 初识面向对象,并完成全选,不选,与反选

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script>
            var choose={
                btns:[],
                box:[],
                xuanze:function(){
                    this.box=document.querySelectorAll('input');
                    return this;
                },
                chooseAll:function(){
                    for(var i=0;i<this.box.length;i++){
                        this.box[i].checked=true;
                    }
                },
                //全选函数
                chooseNo:function(){
                    for(var i=0;i<this.box.length;i++){
                        this.box[i].checked=false;
                    }
                },
                //不选函数
                chooseOr:function(){
                    for(var i=0;i<this.box.length;i++){
                        if(this.box[i].checked){
                            this.box[i].checked=false;
                        }else{
                            this.box[i].checked=true;
                        }
                    }
                }
                //反选函数
            }
            //以下为调用函数
            window.onload=function(){
                var btn=document.querySelectorAll('button');
                btn[0].onclick=function(){
                    choose.xuanze().chooseAll();
                };
                btn[1].onclick=function(){
                    choose.xuanze().chooseNo();
                }
                btn[2].onclick=function(){
                    choose.xuanze().chooseOr();
                }
            } 
        </script>
    </head>
    <body>
        <button>全选</button>
        <button>不选</button>
        <button>反选</button><br>
        <input type="checkbox" name="" id=""><br>
        <input type="checkbox" name="" id=""><br>
        <input type="checkbox" name="" id=""><br>
        <input type="checkbox" name="" id=""><br>
        <input type="checkbox" name="" id=""><br>
        <input type="checkbox" name="" id=""><br>
        <input type="checkbox" name="" id=""><br>
        <input type="checkbox" name="" id=""><br>
        <input type="checkbox" name="" id=""><br>
        <input type="checkbox" name="" id=""><br>
    </body>
    </html>
  • 相关阅读:
    01_计算机基础
    09_哈希表
    08_查找算法
    Swagger使用
    Thymeleaf代码实例
    Spring boot代码实例
    Spring mvc代码实例
    Hibernate代码实例
    Mysql JDBC代码实例
    Mybatis代码实例
  • 原文地址:https://www.cnblogs.com/momomiji/p/7638406.html
Copyright © 2011-2022 走看看