Jquery表单验证不显示消息

时间:2013-11-18 21:09:13

标签: jquery jquery-validate

任何人都可以告诉我为什么这段代码没有显示自定义jquery消息,其他一切都在验证时工作正常但由于某些原因,在输入fx错误的电子邮件时没有出现自定义消息。

************Jquery***************   
<script src="//code.jquery.com/jquery-1.10.1.min.js"></script> 
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>

<script>
            $(document).ready(function() {

    $('#addCustomerForm').validate({
    rules: {
    firstName: {
    required: true

    },
            lastName: {
            required: true

            },
            email: {
                    required: true,
                    email: true

            },
            phone: {
            required: true,
                    digits: true,
                    minlength: 8
            },
            city: {
            required: true,
                    minlength: 2,
                    maxlength: 30
            },
            street: {
            required: true,
                    minlegnth: 2,
                    maxlength: 15
            },
            zipcode: {
            required: true,
                    minlength: 4,
                    maxlength: 4

            },
            country: {
            required: true,
                    minlength: 2,
                    maxlength: 10
            },
            password: {
            required: true,
                    password: true,
                    minlength: 3,
                    maxlength: 15 

            },
            messages: {
            email: {
            required: "We need customers email address to contact",
                    email: "Your email address must be in the format of name@domain.com"
            },
            city : {
            required : " City must be  filled in",
                    minlength : "At least 3 characters long",
                    maxlength : "Should not exceed 30 characters"
            }
            }


    }
    });
            $(window).load(function() {
    $('.log-out').fadeIn(200);
    });
    });

1 个答案:

答案 0 :(得分:1)

你的牙套不合适。您有messages作为rules对象的属性。它应该与rules处于同一级别。

你有这个:

$('#addCustomerForm').validate({
    rules: {
        firstName: { ... },
        ...
        messages: { ... }
    }
});

当你应该这样:

$('#addCustomerForm').validate({
    rules: {
        firstName: { ... },
        ...
    },
    messages: { ... }
});