【问题标题】:jQuery select all checkboxes within table rowjQuery选择表格行中的所有复选框
【发布时间】:2014-06-02 19:56:00
【问题描述】:

我有一个表,每行有多个复选框,我创建了一些 jQuery,通过单击另一个复选框来检查某一行上的所有复选框。

$('table').on('change', '.selectAll', function(e) {
      if(this.checked) {
          $(e.target).closest('tr').find(".aCheckbox").each(function() {
                $(this).attr('checked', true);
          });
      }
      else {
        $(e.target).closest('tr').find(".aCheckbox").each(function() {
                $(this).attr('checked', false);
          });
      }
});

但它只会工作两次(即:您可以选中所有框,取消选中它们,但之后当我再次尝试检查它们时不会发生任何事情)

当我单击我的 .selectAll 复选框时,它会将输入的 html 成功更改为 checked='checked',但看不到任何更改。

这里有什么问题?

谢谢

【问题讨论】:

    标签: javascript jquery html checkbox


    【解决方案1】:

    您需要更改checked 属性,而不是checked 属性。你也不需要迭代,所以我为你简化了函数:

    $('table').on('change', '.selectAll', function (e) {
        $(this).closest('tr').find(".aCheckbox").prop('checked', this.checked);
    });
    

    【讨论】:

      猜你喜欢
      • 2013-10-10
      • 1970-01-01
      • 1970-01-01
      • 2012-05-08
      • 2013-01-29
      • 2013-01-09
      • 1970-01-01
      • 1970-01-01
      • 2014-06-29
      相关资源
      最近更新 更多