jQuery Validate Plugin invalid使输入消失

时间:2013-01-30 19:52:26

标签: jquery jquery-validate

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

JS:

$("#customer-info").validate({
                         debug:true,
                         errorElement: "",
                         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:

<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>

<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

1 个答案:

答案 0 :(得分:1)

我删除debug: trueerrorElement: ''时似乎工作正常。

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>已被弃用多年。