表单无效时禁用提交按钮 [英] Disable submit button when form is invalid
本文介绍了表单无效时禁用提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用jQuery Validate验证的表单.我希望能够在表单无效时禁用提交"按钮,但是我不确定最好的方法.要禁用该按钮,我只需执行此操作
I have a form that I validate with jQuery Validate. I want to be able to disable the submit button when the form is invalid but I am unsure of the best approach. To disable the button I can simply do this
$("#clientConfigurationForm input[type=submit]")
.prop("disabled", !clientConfigValidation.valid());
问题是该代码放在哪里?看来,跟踪所有更改的唯一方法是在unhighlight
和highlight
中都复制代码.
The issue is where do I put this code? It seems that the only way to track all changes is to replicate the code in both unhighlight
and highlight
.
是否有更好的方法来解决此问题?
Is there a better way to approach this issue?
推荐答案
当输入更改时,我将执行它.
I'd execute it when an input is changed.
$('#yourForm input, #yourForm select, #yourForm textarea').on('change', checkForm);
function checkForm(){
$("#clientConfigurationForm input[type=submit]")
.prop("disabled", !clientConfigValidation.valid());
}
这篇关于表单无效时禁用提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文