【问题标题】:toggle required on textfields when checkboxes are checked选中复选框时需要在文本字段上切换
【发布时间】:2018-01-12 13:10:49
【问题描述】:

当单击表格中的任何复选框时,我将所有复选框都设置为选中状态。现在我需要在选中复选框时将所有文本字段设置为必需,并在未选中所有复选框时删除必需。

使用此代码,我检查所有复选框。如何在文本字段字段上切换所需的?

$('.checkAll').click(function (e) {
    $(this).closest('table').find(':checkbox').prop('checked', this.checked);
})

【问题讨论】:

  • 您是否尝试过查找文本字段并执行 prop('required', true) ?
  • 你使用哪个 jquery 版本?

标签: javascript jquery checkbox toggle textfield


【解决方案1】:

只需将其插入您的代码中即可。

$("input:text").prop('required',true);

例子:

$('.checkAll').click(function (e) {
    $(this).closest('table').find(':checkbox').prop('checked', this.checked);
    $("input:text").prop('required', true);
})

或者您可以将"input:text" 替换为您需要的每个文本字段上的类

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-18
    相关资源
    最近更新 更多