jQuery .submit()验证问题 [英] jquery .submit() validate problem

查看:89
本文介绍了jQuery .submit()验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我编写的此验证内容有效,但由于某种原因,我需要单击两次以提交表单.有什么想法吗?

So this validation thing I wrote works but for some reason I need to click twice for the form to submit. Any ideas?

        $('#signup').submit(function() {
        console.log('Clicked');
    $('#signup').validate({
            rules: {
    FNAME: {
        required: true,
        notPlaceholder: true
    },
    email: {
        required: true,
        notPlaceholder: true,
        email: true
    }
},
        errorLabelContainer: "div.error",
        submitHandler: function(form) {
            $.colorbox({width:"300px", href:'thankyou.html'});
            $('#signup').fadeOut();
        }
    });
    return false;
});

谢谢

推荐答案

您的$('#signup').validate调用位于内部 $('#signup').submit,这意味着直到用户首次尝试验证器才被附加提交表格.正如Cyber​​nate在评论中指出的那样,将validate调用移到submit调用之前将首先附加验证器.

Your $('#signup').validate call is inside $('#signup').submit, which means the validator isn't attached until the first time the user tries to submit the form. As Cybernate pointed out in a comment, moving the validate call before the submit call will attach the validator first.

有点混乱; validate实际上是设置验证,而不是立即执行.

It's a little confusing; validate actually sets up validation, rather than performs it right away.

使用validate设置验证后,您实际上可以将submit调用更改为如下形式:

Once validation has been set up using validate, you can actually change your submit call to look like this:

$('#signup').submit(function() {
  return $('#signup').valid();
});

这篇关于jQuery .submit()验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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