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>
  • 相关阅读:
    33 函数参数的传递方式
    33 函数递归调用
    32 头文件
    31 函数
    30 枚举
    centos6.5升级默认的Mysql到5.5方法
    Centos6.5命令行快捷键
    redhat 安装lamp
    CentOS6.5中的vsftpd安装配置
    添加一个用户并且让用户获得root权限
  • 原文地址:https://www.cnblogs.com/momomiji/p/7638406.html
Copyright © 2011-2022 走看看