覆盖onError和onSuccess jquery验证不显眼

时间:2013-10-28 15:04:56

标签: jquery asp.net-mvc-4 jquery-validate unobtrusive-validation

现在我在jquery.valiadte.unobtrusive.js中修改onerror和onsucces方法,如下所示:

 function onSuccess(error) {  // 'this' is the form element
    var container = error.data("unobtrusiveContainer"),
        replace = $.parseJSON(container.attr("data-valmsg-replace"));

    if (container) {
        container.addClass("field-validation-valid").removeClass("field-validation-error");
        error.removeData("unobtrusiveContainer");
        var parent = container.parent();
        parent.css("display", "block");
        parent.addClass("validLabel").removeClass("invalidLabel");
        parent.children().css("display", "none");
        var label = parent.parent().children("label:first-child,.label:first-child");
        label.removeClass("errorLabel");
        var info = parent.parent().children(".infoLabel");
        info.css("display", "none");
        $("#aCGVValidate").removeClass("validLabel");
        if (replace) {
            container.empty();
        }
    }
}

并出错:

 function onError(error, inputElement) {  // 'this' is the form element
    var container = $(this).find("[data-valmsg-for='" + inputElement[0].name + "']"),
        replace = $.parseJSON(container.attr("data-valmsg-replace")) !== false;

    container.removeClass("field-validation-valid").addClass("field-validation-error");
    error.data("unobtrusiveContainer", container);
    var parent = container.parent();
    parent.css("display", "block");
    parent.addClass("invalidLabel").removeClass("validLabel");
    parent.children().css("display", "inline-block");
    error.data("unobtrusiveContainer", container);
    var label = parent.parent().children("label:first-child,.label:first-child");
    label.addClass("errorLabel");
    var info = parent.parent().children(".infoLabel");
    info.css("display", "none");
    if (replace) {
        container.empty();
        error.removeClass("input-validation-error").appendTo(container);
    }
    else {
        error.hide();
    }
}

我需要在库外进行修改才能改变样式,如何在lib之外覆盖这些方法? (我的目标是让css像这样:)enter image description here

1 个答案:

答案 0 :(得分:1)

我使用highlight, unhighlight回调函数