开发者

Can I have a submit button on a form that overrides/ignores jquery.validate plugin? [duplicate]

This question already has answers here: 开发者_运维问答 jQuery Validation plugin: disable validation for specified submit buttons (12 answers) Closed 8 years ago.

I've got an html form that is being validated using jquery validate plugin. The form has 3 submit buttons. Each submit button causes the page to do something a little different. I'd like for one of the three submit buttons to just submit the form and completely ignore the validation routine I've built using the jQuery validation plugin. Is this possible?

Thanks


For the submit buttons, you can unbind events on that DOM element, then bind your own function. Also, make sure that your function returns false or it will submit the form.

http://api.jquery.com/bind/

Also, see:

http://api.jquery.com/event.stopPropagation


Yes, it is possible. You test the ID of the clicked submit button, and use the click event to perform the form submission, or the validation, depending on which button has been clicked:

$("#form input:submit").click(function(e) {
    if (e.target.id == "foo") { // or this.id, or $(this).attr('id')
        alert("submitting");
        $(this).closest("form").submit();
    } else {
        alert("do the validation");
        return false;
    }
});

Demo: http://jsfiddle.net/karim79/VmX3R/3/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜