Preventing a form from submitting in jQuery Validate plugin's submitHandler function

后端 未结 8 1651
花落未央
花落未央 2020-12-08 07:24

I am using jQuery with the validate plugin at http://docs.jquery.com/Plugins/Validation/validate

I want to prevent the form from submitting after its validation and

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 08:02

    I do it like this and it works exactly how you want it to work:

    $("#myform").submit(function(e) {
        e.preventDefault();
    }).validate({
        rules: {...},
        submitHandler: function(form) { 
            alert("Do some stuff...");
            //submit via ajax
            return false;  //This doesn't prevent the form from submitting.
        }
    });
    

提交回复
热议问题