0

我有一个简单的表格,需要确认电子邮件,如果没有错误,它会很好用。但是,如果我提交错误 jquery 验证插件正在添加 display:none 到确认电子邮件输入。它不会添加无效的类,不确定发生了什么。

JS:

$("#customer-info").validate({
                         调试:真,
                         错误元素:“”,
                         提交处理程序:函数(表单){
                             //TODO需要一个处理图像
                             $.post(form.action, $(form).serialize(), function(result) {
                                 如果(结果 > 0){
                                         // 做一些事情
                                     }
                             },"json")
                             返回假;
                         }
                });

html:

<form id="customer-info">
    <label for="customer-name">Name</label>
        <input type="text" id="customer-name" name="customer-name" placeholder="first last name" class="required" /><br />
        <label for="customer-email">Email</label>
        <input type="text" id="customer-email" name="customer-email" placeholder="email@gmail.com" class="required email" /><br />
        <label for="confirm-email">Confirm Email</label>
        <input type="text" id="confirm-email" name="confirm-email" placeholder="email@gmail.com" class="required email" equalTo="#customer-email" /><br />
        <label for="notes">Notes</label>
        <textarea id="notes" name="notes" placeholder="Any additional details or changes."></textarea><br />
        <center><input type="submit" value="Go" class="btn-go" /></center>
</form>

http://docs.jquery.com/Plugins/Validation

4

1 回答 1

1

debug: true当我删除and时,它似乎工作正常errorElement: ''

当您定义errorElement''(无)时,您会破坏它。

默认情况下,它是errorElement: 'label'.

工作演示:http: //jsfiddle.net/vHKha/

$(document).ready(function () {
    $("#customer-info").validate({
        submitHandler: function (form) {
            //TODO need a processing image
            $.post(form.action, $(form).serialize(), function(result) {
                if(result > 0){
                    // do some stuff
                }
            },"json")
            return false;
        }
    });
});

旁注: 您可能还想验证您的 HTML。 <center></center>已被弃用多年。

于 2013-01-30T23:27:01.963 回答