码迷,mamicode.com
首页 > 其他好文 > 详细

初识面向对象,并完成全选,不选,与反选

时间:2017-10-08 21:25:15      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:log   cli   select   对象   cto   return   cti   button   反选   

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

 

初识面向对象,并完成全选,不选,与反选

标签:log   cli   select   对象   cto   return   cti   button   反选   

原文地址:http://www.cnblogs.com/momomiji/p/7638406.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!