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>
  • 相关阅读:
    javascript学习笔记-数据类型
    chrome console.log API
    Mysql下SELECT的结果集作为UPDATE的WHERE条件时的SQL语法
    Ajax、Comet、Websocket、SSE
    Model View Controller(MVC) in PHP
    区别Transform、Transition、Animation
    WAI-ARIA无障碍网页应用属性完全展示
    理解 PHP output buffer
    清除Jquery动画的队列
    git常用命令
  • 原文地址:https://www.cnblogs.com/momomiji/p/7638406.html
Copyright © 2011-2022 走看看