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');
                }
            });
        });
    });

  • 相关阅读:
    markdown样式代码保存
    【python系统学习08】for循环知识点合集
    【python系统学习07】一张图看懂字典并学会操作
    【python系统学习06】一张图看懂列表并学会操作
    java后端学习记录
    支付功能设计及实现思路
    《Kafka权威指南》读书笔记
    ReentrantLock源码简析
    敏捷开发流程
    上线新功能,如何兼容旧数据?
  • 原文地址:https://www.cnblogs.com/baobeiqi-e/p/9884833.html
Copyright © 2011-2022 走看看