【问题标题】:How to validate in jQuery first before calling the server side如何在调用服务器端之前先在 jQuery 中进行验证
【发布时间】:2016-02-04 01:24:34
【问题描述】:

目前,我使用的是http://jqueryvalidation.org/,我有这个表格

<form action="AddDefectToDatabaseServlet" method="post" id="myForm">

然后在我的js脚本中

$(document).ready(function() {

$('#myform').validate({ // initialize the plugin
    rules: {
        title: {
            required: true
        },
        description: {
            required: true
        }
    },
    errorPlacement: function(){
        return false;
    },
    submitHandler: function (form) { // for demo
        alert('valid form submitted'); // for demo
        return false; // for demo
    }
 });

});

但我的问题是,即使验证错误,它也会一直到服务器端,对不起,我是这个插件的新手,

【问题讨论】:

标签: javascript jquery html formvalidation-plugin


【解决方案1】:

您缺少一个 invalidHandler。

来自文档 - http://jqueryvalidation.org/validate

invalidHandler
Type: Function()
Callback for custom code when an invalid form is submitted. Called with an event object as the first argument, and the validator as the second.

【讨论】:

    猜你喜欢
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-23
    • 1970-01-01
    • 2016-09-25
    相关资源
    最近更新 更多