jQuery禁用按钮(不提交),直到字段验证+验证插件 [英] jQuery disable button (NOT Submit) until field validates + Validation Plugin

查看:85
本文介绍了jQuery禁用按钮(不提交),直到字段验证+验证插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单上有4个按钮,即提交",取消",添加"和删除"按钮.一切都按预期工作,但是我想禁用添加"按钮,直到输入字段通过验证.我使用的是Validation插件,我认为可以通过回调进行必需的验证来完成此操作,但是我不确定.

I have 4 buttons on my form, a Submit, Cancel, Add and Remove button. All are working as expected but I would like to disable the Add button until the input field validates. I'm using the Validation plug-in and I think this can be done with a required validation with a callback but I'm not sure.

有人能指出我正确的方向吗?

Could someone point me in the right direction?

更新:

这是一些代码的想法

required: function(element) { 
   return($('#chargeamtaddButton').attr('disabled', ? '','disabled');
}

寻找该true/false选项标记以设置禁用的属性

Looking for that true/false option flag to set the disabled attribute

推荐答案

我以前使用过验证插件,但我不记得所有详细信息.我很确定这是这样的:

I've used the validation plugin before but I can't remember all the details. I'm pretty sure it's something like this:

$(function() {
    $('#myForm').validate(
        rules: {
            'elementToWatch': {
                success: function(element) { 
                    if($("#myform").validate().element("#myselect")) {
                        $('#chargeamtaddButton:disabled').removeAttr('disabled');
                    } else {
                        $('#chargeamtaddButton').attr('disabled','disabled');
                    }
                },
                // etc...
             },
             // etc...
         },
         // etc...
     });
 });

由于有很多使用验证插件的方法,很难为您提供完美的建议,但是我希望我所展示的内容能为您提供一个更好的前进方向的想法.也许如果您提供更多的代码和HTML,我可以为您提供更多帮助.

Since there are so many ways to use the validation plugin, it's hard to give you perfect advice but I hope what I've shown gives you a better idea of how to move forward. Maybe if you gave some more code and HTML, I could help you out more.

这篇关于jQuery禁用按钮(不提交),直到字段验证+验证插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆