zoukankan      html  css  js  c++  java
  • JQuery CheckBoxList

    JQuery CheckBoxList

    引自:http://www.cnblogs.com/RuiLei/archive/2009/08/28/1555776.html

    CheckBoxList全选,反选,

    第一种

    全选

        $(".checkBoxSelect").each(function() {
                    $(this).attr("checked", true); 
         });

    反选

         $(".checkBoxSelect").each(function() {
                            if($(this).attr("checked"))
                            {
                                    $(this).attr("checked", false);
                            }
                            else
                            {
                                    $(this).attr("checked", true);
                            }
                    });

    第二种

    全选

        $("#<%=CheckBoxList.ClientID %> input:checkbox").each(function(index,domEle){ 
                  if(this.type=="checkbox")
                       this.checked=true;
        });
    反选
        $("#<%=CheckBoxList.ClientID %> input:checkbox").each(function(index,domEle){ 
                 if(this.type=="checkbox")
                      this.checked=!this.checked;
        });
    第三种
         使用toggle方式进行全选、反选

               btnSelAll.click(function() {
                   jqClass.toggleChecks(null);
               });

               var jqClass= {
                     //Toggle Item For CheckBoxList
                     toggleChecks: function(b) {
                              $("#<%=cblContact.ClientID %> input[type=checkbox]").each(function() {
                                        if (typeof this.checked != "undefined") {
                                                  if (b == null)
                                                        this.checked = (!this.checked);
                                                  else
                                                        this.checked = b;
                                         }
                                });
                  }
           }

    第四种:Plugin 方式

    (function($$) {
        $.fn.jCheckboxList = function(opt) {
            var option = {
                root: '',  //  checkbox id of "select all"
                childCls: ''  // another checkboxs
            };
            var opt = $.extend({}, option, opt);
            var el = $(this).attr('id');
            var allchild = "#" + el + " :input[type=checkbox]." + opt.childCls;
            $("#" + opt.root).click(function() {
                var isChecked = $(this).attr('checked');
                if (isChecked)
                    $(allchild).attr('checked', true);
                else
                    $(allchild).attr('checked', false);
            });

            $.each($(allchild), function(i, v) {
                var all = $(allchild).length;
                $(v).click(function() {
                    var count = $(allchild + "[checked]").length;
                    if (count == all)
                        $("#" + opt.root).attr('checked', true);
                    else
                        $("#" + opt.root).attr('checked', false);
                });
            });
        }
    })();

  • 相关阅读:
    luogu P4284 [SHOI2014]概率充电器 期望 概率 树形dp
    luogu P5161 WD与数列 SAM 线段树合并 启发式合并
    5.5 省选模拟赛 B Permutation 构造 贪心
    luogu P3761 [TJOI2017]城市 树的直径 bfs
    一本通 1783 矩阵填数 状压dp 容斥 计数
    CF R638 div2 F Phoenix and Memory 贪心 线段树 构造 Hall定理
    BSOJ 5445 -- 【2018雅礼】树 prufer序列 dp
    CF1037H Security 线段树合并 SAM
    c++11の顺序容器
    c++11の关联容器
  • 原文地址:https://www.cnblogs.com/sgivee/p/1744858.html
Copyright © 2011-2022 走看看