zoukankan      html  css  js  c++  java
  • jQuery使用prop设置checkbox全选、反选

    $(document).ready(function(){
                $("#allsel").click(function(){
                /*
                    var is = $(this).attr("checked");
                    if(is=="checked"){
                    $("table :checkedbox").attr("checked",true);
                    }
                */
                //prop
                var is =$(this).prop("checked");
                $("table :checkbox").prop("checked",is);
                
                });
                
                
                $("#notsel").click(function(){
                    $("table :checkbox").prop("checked",function(index,attr){
                        return !attr;
                    
                    });
                
                }
                
                );

            });




    $(function(){
        var checkbox = $("input[type='checkbox']");
        //全选
        $('#select-all').click(function(){
            checkbox.attr('checked', true);
        });

        //反选
        $('#select-reverse').click(function(){
            checkbox.each(function(i, dom){
                if ( $(dom).attr('checked') ) {
                    $(dom).removeAttr('checked');
                } else {
                    $(dom).attr('checked', 'checked');
                }
            });
        });
    });

  • 相关阅读:
    单例模式创建
    盛最多水的容器
    魔术索引
    钢条切割
    比较版本号
    矩阵中的路径
    机器人的运动范围
    计网基础问题
    Linux 下android环境的配置
    Fedora15下安装Android开发环境
  • 原文地址:https://www.cnblogs.com/baobeiqi-e/p/9884833.html
Copyright © 2011-2022 走看看