zoukankan      html  css  js  c++  java
  • jquery复选框操作

    $('input[type="checkbox"]').change(function(e) {
    
      var checked = $(this).prop("checked"),
          container = $(this).parent(),
          siblings = container.siblings();
    
      container.find('input[type="checkbox"]').prop({
        indeterminate: false,
        checked: checked
      });
    
      function checkSiblings(el) {
    
        var parent = el.parent().parent(),
            all = true;
    
        el.siblings().each(function() {
          return all = ($(this).children('input[type="checkbox"]').prop("checked") === checked);
        });
    
        if (all && checked) {
    
          parent.children('input[type="checkbox"]').prop({
            indeterminate: false,
            checked: checked
          });
    
          checkSiblings(parent);
    
        } else if (all && !checked) {
    
          parent.children('input[type="checkbox"]').prop("checked", checked);
          parent.children('input[type="checkbox"]').prop("indeterminate", (parent.find('input[type="checkbox"]:checked').length > 0));
          checkSiblings(parent);
    
        } else {
    
          el.parents("li").children('input[type="checkbox"]').prop({
            indeterminate: true,
            checked: false
          });
    
        }
    
      }
    
      checkSiblings(container);
    });
  • 相关阅读:
    Day Six(Beta)
    Day Five (beta)
    Day Four(Beta)
    Day Three(Beta)
    Day Two(Beta)
    Day One(Beta)
    项目冲刺——总结
    beta版本贡献率
    软件工程实践总结
    团队作业--Beta版本冲刺
  • 原文地址:https://www.cnblogs.com/xuxiaoshuan/p/5508776.html
Copyright © 2011-2022 走看看