jquery validate 中highlight和unhighlight使用

$(document).ready(function () {
            $('span.required').find('input').addClass('required');

            $('#form1').validate({
                rules: {
                    txbCnfEmail: {
                        required: true,
                        email: true,
                        equalTo: "#txbEmail"
                    }
                },
                messages: {
                    txbFirstname: "Please enter your First Name",
                    txbLastname: "Please enter your Last Name",
                    txbAddress1: "Please enter your Mailing Address 1",
                    txbSuburb: "Please enter your Suburb",
                    ddlCountry: "Please select your country",
                    txbPostcode: {
                        required: "Please enter your Postcode",
                        number: "Please enter a valid Postcode"
                    },
                    ddlGender: "Please select your Gender",
                    ddlAge: "Please select your Age",
                    ddlHearFrom: "Please select",
                    txbEmail: {
                        required: "Please enter your Email Address",
                        email: "Please enter a valid Email Address"
                    },
                    txbCnfEmail: {
                        required: "Please enter a valid Confirm Email Address",
                        email: "Please enter a valid Confirm Email Address",
                        equalTo: "Confirm email address doesn't match the email address"
                    }
                },
                errorLabelContainer: "#error", 
                highlight: function (element, errorClass) {
                    $(element).addClass(errorClass);
                    $("#error").find("label[for=" + element.id + "]")
                    .addClass(errorClass);
                    $(element).prev('label').addClass('error2');
                },
                unhighlight: function (element, errorClass) {
                    $(element).removeClass(errorClass);
                    $("#error").find("label[for=" + element.id + "]")
                    .removeClass(errorClass).css("display", "none");
                    $(element).prev('label').removeClass('error2');
                }
            });
        });

 

posted on 2012-06-08 14:58  魔GUI  阅读(1706)  评论(0编辑  收藏  举报

导航