开发者

Trigger jQuery Validation Manually?

I have i form i submit via jQuery's .submit(), unfortunately it does not trigger the validation plugin when i do it this way. If i place a submit button开发者_C百科 inside the form, it works perfectly.

Is there someway to trigger the plugin manually?

Thanks in advance.


$("#myButton").click(function(e) {
    e.preventDefault();
    if($("#myform").valid()){
        // the form is valid, do something
    } else{
        // the form is invalid
    }
});


You can use this

$(".selector").validate({
   submitHandler: function(form){
    form.submit();
   }
});

which autosubmits the form it is valid, so you .validate() instead of submit()


You could try this:

$('#someForm').valid();

which could also be done in the submit handler:

$('#someForm').submit(function() {
    if ($(this).valid()) {

    } else {

    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜