在jquery小部件中覆盖方法

Cod*_*kie 5 javascript jquery

我正在尝试覆盖jquery小部件中的方法.该方法可以在第122行的https://github.com/got5/tapestry5-jquery/blob/master/src/main/resources/org/got5/tapestry5/jquery/validation.js找到.

我想改变第141行的html输出

我尝试将以下内容添加到我的自定义js类中但没有成功.如果有人能解释如何做到这一点,我非常感激.

(function($) {    
$.widget( "ui.tapestryFieldEventManager", {
    showValidationMessage : function(message) {
        var field = this.element;
        var form = field.closest('form');

        this.options.validationError = true;
        form.formEventManager("setValidationError", true);

        field.addClass("t-error");

        this.getLabel() && this.getLabel().addClass("t-error");

        var icon = this.getIcon();

        if (icon) icon.show();
        alert("here");
        var id = field.attr('id')+"\\:errorpopup";
        if($("#"+id).size()==0) //if the errorpopup isn't on the page yet, we create it
            field.after("<div id='"+field.attr('id')+":errorpopup' class='tjq-error-popup test'/>");
        Tapestry.ErrorPopup.show($("#"+id),"<span>"+message+"</span>");

    }
});
})(jQuery);
Run Code Online (Sandbox Code Playgroud)

use*_*654 9

你必须在原型上覆盖它.

var oldMethod = $.ui.tapestryFieldEventManager.prototype.showValidationMessage;    
$.ui.tapestryFieldEventManager.prototype.showValidationMessage = function (message) {
    // do your stuff here
    alert("worky");

    // apply old method
    oldMethod.apply(this,arguments);
};
Run Code Online (Sandbox Code Playgroud)

当然,如果您的新方法执行旧方法所做的所有操作,您可以跳过应用旧方法.