jquery禁用表单除了一个复选框

时间:2015-08-29 21:26:18

标签: jquery

我有表单我正在按表单标记禁用所有字段,除非满足某个条件。我想禁用整个表单(工作)但是我想要按类(不工作)启用一组复选框吗?见下文

if (sharesNegative=1) {
    moAlert('Negative Share:','If Account Number Reassignment is not due to fraud,\
bring all shares positive before changing account number.' );
    $('form[name=accountChange]').prop('disabled',true);
    $('.fraudYesNo').prop('disabled',false); //not working 
}

2 个答案:

答案 0 :(得分:0)

使用:input选择器。

$("form[name=accountChange] :input").prop("disabled", true);

答案 1 :(得分:0)

您不能禁用表单,只能禁用表单元素。

$('#disabler').on('click', function(){
  $(':input').prop('disabled',true);
  $('.fraudYesNo').prop('disabled',false); 
});

此处示例:http://jsfiddle.net/y8ffe8gw/,HTML规范:https://html.spec.whatwg.org/#the-form-element

此外,虽然不是您的问题的一部分,但请注意if (sharesNegative=1) {始终为true,因为只有一个=您正在分配变量的值。您想使用==来比较if (sharesNegative==1) {...}

相关问题