您当前的位置: 首页 >  Java

命运之手

暂无认证

  • 2浏览

    0关注

    747博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Javascript】【jQuery】通过jQuery方法扩展,简化全选功能代码

命运之手 发布时间:2019-05-08 11:26:50 ,浏览量:2


    
        Item
        Item
        Item
        Item
        Item
        
        Check
        Uncheck
        Reverse
    

    
        $(function () {
            //给jQuery结果集对象扩展全选方法
            var actionHandler = {
                check: function () {
                    //全部选择
                    this.prop("checked", true);
                },
                uncheck: function () {
                    //全部取消
                    this.prop("checked", false);
                },
                reverse: function () {
                    //逐个反选
                    this.each(function () {
                        this.checked = !this.checked;
                    });
                }
            };
            jQuery.fn.extend(actionHandler);

            //绑定事件
            $("#bt-check").click(() => {
                $(".item").check();
            });
            $("#bt-uncheck").click(() => {
                $(".item").uncheck();
            });
            $("#bt-reverse").click(() => {
                $(".item").reverse();
            });
        });
    

关注
打赏
1654938663
查看更多评论
立即登录/注册

微信扫码登录

0.0378s