Overriding jQuery plugin methods, as default and for single instances

左心房为你撑大大i 提交于 2019-12-05 17:56:11
jAndy
(function($){

var _oldcss = $.fn.css;

$.fn.css = function(prop,value){

    if (value.toLowerCase() === 'somecolor') {
       return _oldcss.call(this,prop,'#EA7E5D');
    } else {
       return _oldcss.apply(this,arguments);
    }
};
})(jQuery);

You can easily overwrite (I like to call it semi-hooking) functions in that manner. In this example, you overwrite the .css() jQuery function and return a custom value of your value equals 'somecolor', otherwise, the original function is called with passed arguments.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!