JavaScript无侵入拓展组件功能

通过自定义拓展方法,可以增强js组件功能。

jQuery.fn.valid = function(_this){
    return function(){
        var _valid = _this.call(this);
        if(!OPC.DEBUG && !_valid){
            setTimeout(() => {
                $(this).validate().focusInvalid();
            }, 168);
            //this.find("input").filter('.error:first').focus();
        }
        return !OPC.DEBUG ? _valid : true;
    };
}(jQuery.fn.valid);
// 拓展功能
$.validator.prototype.focusInvalid = function (_this) {
    return function(){
        _this.call(this);
        OPC.LADDA.stopAll();
    };
}($.validator.prototype.focusInvalid);

你可能感兴趣的:(JavaScript无侵入拓展组件功能)