jquery Validation 插件

官方文档地址:http://docs.jquery.com/Plugins/Validation

官方下载地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation/

$(document).ready(function () {
    jQuery.validator.addMethod('CheckCheckBoxList',
            function (value, element) {
                var checkedLength = $("#" + chklMemberGuardianship + " input:checked").length;
                if (checkedLength > 0)
                    return true;
                if ($("#" + dropServiceCombo).val() != "-1")
                    return true;
                else
                    return false;
            },
           Remp_PleaseChoose
        );

    $.validator.setDefaults({
        submitHandler: function (form) {
            if ($(formid).validate.cancelSubmit || $(formid).valid()) {
                form.submit();
            }
        }
    });

    var formid = $("form").first();
    $(formid).validate({
        errorElement: "em",
        errorPlacement: function (error, element) {
            if (element.is(":radio"))
                error.appendTo(element.parent().next().next());
            else if (element.is(":checkbox")) {
                var checkship = $("#" + chklMemberGuardianship);
                error.appendTo(checkship.parent());
            }
            else
                error.appendTo(element.parent());
        }
    });

    //验证规则
    $("#" + txtMemberID).rules("add", { required: true, CheckHtml: true, CheckMemberIDIsExists: true, messages: { required: Remp_NotNull} });
    $("#" + txtIntervalPeriod).rules("add", { required: true, digits: true, min: 1, messages: { required: Remp_NotNull, digits: Remp_ValidIntPostiveErrorInfo, min: Remp_ValidIntPostiveErrorInfo} });
    $("#" + txtBeginDate).rules("add", { required: true, messages: { required: Remp_NotNull} });
    $("#" + txtMemberGroup).rules("add", { CheckHtml: true });
    $("#" + dropParentOrgID).rules("add", { CheckSelect: true });
    $("#" + dropServicePeriod).rules("add", { CheckSelect: true });
    $("#" + chklMemberGuardianship + "_1").rules("add", { CheckCheckBoxList: true });
    $("#" + txtMemberGroup).rules("add", { CheckMemberGroup: true });
    $("#" + edate).rules("add", { CheckEndDate: true });
});

 

posted @ 2011-10-18 15:22  虎头  阅读(375)  评论(0编辑  收藏  举报