Jquery 选择具有不确定特征的多个复选框

Jquery 选择具有不确定特征的多个复选框,jquery,checkbox,Jquery,Checkbox,我在上实现了一个小脚本 但是我的html包含一个 我的剧本是 <script> $(function() { // Apparently click is better chan change? Cuz IE? $('input[type="checkbox"]').change(function(e) { var checked = $(this).prop("checked"), container = $(this).p

我在上实现了一个小脚本 但是我的html包含一个

  • 我的剧本是

    <script>
    $(function() {
      // Apparently click is better chan change? Cuz IE?
      $('input[type="checkbox"]').change(function(e) {
      var checked = $(this).prop("checked"),
          container = $(this).parent().parent(),
          siblings = container.siblings();
      container.find('input[type="checkbox"]').prop({
          indeterminate: false,
          checked: checked
      });
     function checkSiblings(el) {
          var parent = el.parent(),
              all = true;
          console.log(parent);
          el.siblings().each(function() {
               all = ($(this).children('input[type="checkbox"]').prop("checked") === checked);
              console.log(all);
              return all;
          });
    
          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));
              //console.log("thi sis ");
              checkSiblings(parent);
          } else {
              el.parents("li").children('input[type="checkbox"]').prop({
                  indeterminate: true,
                  checked: false
              });
              console.log("apple");
          }
        }
    
    
        checkSiblings(container);
      });
    });
    </script>
    
    
    $(函数(){
    //显然点击是更好的改变?因为IE?
    $('input[type=“checkbox”]”)。更改(函数(e){
    var checked=$(this).prop(“checked”),
    容器=$(this).parent().parent(),
    兄弟姐妹=容器。兄弟姐妹();
    container.find('input[type=“checkbox”]”).prop({
    不确定:错误,
    勾选:勾选
    });
    功能检查(el){
    var parent=el.parent(),
    全部=正确;
    console.log(父级);
    el.sides().each(函数()){
    all=($(this).children('input[type=“checkbox”]”).prop(“checked”)==checked);
    控制台日志(全部);
    全部归还;
    });
    如果(全部选中(&D){
    parent.children('input[type=“checkbox”]”).prop({
    不确定:错误,
    勾选:勾选
    });
    检查兄弟姐妹(父母);
    }else if(全部&!选中){
    parent.children('input[type=“checkbox”]”).prop(“checked”,checked);
    parent.children('input[type=“checkbox”]')).prop(“不确定”,“parent.find”('input[type=“checkbox”]:checked')).length>0);
    //控制台日志(“thisis”);
    检查兄弟姐妹(父母);
    }否则{
    el.parents(“li”).children('input[type=“checkbox”]”).prop({
    不确定:对,
    勾选:假
    });
    console.log(“苹果”);
    }
    }
    支票(集装箱);
    });
    });
    
    您可能希望从输入周围删除那些
    标记。如果您将link href作为复选框的数据属性,则仍然可以通过jQuery的输入链接用户,如下所示:

    HTML


    我找到了解决办法。问题是很难找到儿童输入框。 现在,如果列表中包含标签,下面的代码将起作用

    $(function() {
      // Apparently click is better chan change? Cuz IE?
      $('input[type="checkbox"]').change(function(e) {
      var checked = $(this).prop("checked"),
          container = $(this).closest("li"),
          siblings = container.siblings();
          container.find('input[type="checkbox"]').prop({
          indeterminate: false,
          checked: checked
      });
          if(checked)
          {
                      var value= $(this).val();
                      loadMarkers();
                      console.log(value);
    
    
          }
      function checkSiblings(el) {
          //console.log(el);
          var parent = el.parent().parent(),
              all = true;
          el.siblings().each(function() {
              return all = ($(this).children().children().closest('input[type="checkbox"]').prop("checked") === checked);
          });
    
          if (all && checked) {
              parent.children().children().closest('input[type="checkbox"]').prop({
                  indeterminate: false,
                  checked: checked
              });
              checkSiblings(parent);
          } else if (all && !checked) {
              parent.children().children().closest('input[type="checkbox"]').prop("checked", checked);
              parent.children().children().closest('input[type="checkbox"]').prop("indeterminate", (parent.find('input[type="checkbox"]:checked').length > 0));
              checkSiblings(parent);
          } else {
              el.parents("li").children().children().closest('input[type="checkbox"]').prop({
    
    //el.parents('input[type=“checkbox”]')。prop({ //el.parents(“li”).children().find('input[type=“checkbox”]”).prop({ 不确定:对, 勾选:假 }); } }

        checkSiblings(container);
      });
    });
    

    我有另一个脚本附加到它。所以标签是必要的。任何进一步的解决方案是欢迎的。
    $('input[type="checkbox"]').click(function() {
        location.href = $(this).data('href');  
    });
    
    $(function() {
      // Apparently click is better chan change? Cuz IE?
      $('input[type="checkbox"]').change(function(e) {
      var checked = $(this).prop("checked"),
          container = $(this).closest("li"),
          siblings = container.siblings();
          container.find('input[type="checkbox"]').prop({
          indeterminate: false,
          checked: checked
      });
          if(checked)
          {
                      var value= $(this).val();
                      loadMarkers();
                      console.log(value);
    
    
          }
      function checkSiblings(el) {
          //console.log(el);
          var parent = el.parent().parent(),
              all = true;
          el.siblings().each(function() {
              return all = ($(this).children().children().closest('input[type="checkbox"]').prop("checked") === checked);
          });
    
          if (all && checked) {
              parent.children().children().closest('input[type="checkbox"]').prop({
                  indeterminate: false,
                  checked: checked
              });
              checkSiblings(parent);
          } else if (all && !checked) {
              parent.children().children().closest('input[type="checkbox"]').prop("checked", checked);
              parent.children().children().closest('input[type="checkbox"]').prop("indeterminate", (parent.find('input[type="checkbox"]:checked').length > 0));
              checkSiblings(parent);
          } else {
              el.parents("li").children().children().closest('input[type="checkbox"]').prop({
    
        checkSiblings(container);
      });
    });