-1

当类“ui-state-error”时,如何触发 h5Validate 并显示(“#error-email”)

当 h5Validate 添加类时,我需要显示错误。

我的例如:http: //jsfiddle.net/hsSru/30/

谢谢

4

1 回答 1

0

您可以覆盖 addClass 以触发事件:

(function(){
    // Your base, I'm in it!
    var originalAddClassMethod = jQuery.fn.addClass;

    jQuery.fn.addClass = function(){
        // Execute the original method.
        var result = originalAddClassMethod.apply( this, arguments );

        this.trigger('classChanged');

        // return the original result
        return result;
    }
})();

然后你可以做你的事情:

$("#error-email").bind('classChanged', data, function(){
    if(this.hasClass("ui-state-error")){
        //do your stuff
    }
});
于 2012-03-09T16:52:54.570 回答