即使元素被禁用,jQuery验证插件也会导致元素验证失败

即使元素被禁用,jQuery验证插件也会导致元素验证失败,jquery,validation,Jquery,Validation,下面是HTML代码片段的示例: <select name="paytitle" id="paytitle"> <option value="Budget Keeper" selected>Budget Keeper</option> <option value="Bookkeeper">Bookkeeper</option> <option value="Treasurer">Treasurer<

下面是HTML代码片段的示例:

<select name="paytitle" id="paytitle">
    <option value="Budget Keeper" selected>Budget Keeper</option>
    <option value="Bookkeeper">Bookkeeper</option>
    <option value="Treasurer">Treasurer</option>
    <option value="Accounts Payable">Accounts Payable</option>
    <option value="Other">Other</option>
</select>
<div id="otherfield">Other: <input name="paytitleother" type="text" id="paytitleother" class="required" /></div>
当我尝试提交表单时,paytitleother字段仍然未通过验证,即使它已被禁用和隐藏。关于验证插件的文档说明自动忽略所有禁用的字段,但我执行了额外的步骤,将
忽略:“:disabled”
添加到验证例程中:

$('#fieldForm').validate({
    ignore: ':disabled',
    ...
});

即使使用此规范,字段的验证也会失败。我在这个项目上工作了一整天,所以我可能忽略了一些简单的事情,但我看不见它,也无法了解我的一生发生了什么。

当设置
disabled
属性时,尝试使用“disabled”值而不是
true
,就像这样:

$("#paytitleother").attr("disabled", "disabled");

.attr()
上有一些关于如何在HTML4和XHTML中设置“disabled”属性的注释,甚至还有一些关于HTML5的思考。

谢谢-我读到了关于哪个方法(true和“disabled”)的冲突信息使用,我尽量远离前端开发-这与意识到设计师没有预设所有隐藏元素的初始状态为禁用相结合,首先修复了我的所有问题
$("#paytitleother").attr("disabled", "disabled");