Extending an existing jQuery function
I am trying to write a plugin that will extend an existing function in jQuery, eg
(function($)
{
$.fn.css = function()
{
// stuff I will be extending
// that doesn't affect/change
// the way .css() works
};
})(jQuery);
There are only a few bits I need to extend of the .css()
function. Mind me for asking, I was thinking about PHP classes since you can className extend existingClass
, so I'm asking if it's possible to extend jQuery functions.
当然...只需保存对现有函数的引用,然后调用它:
(function($)
{
// maintain a reference to the existing function
var oldcss = $.fn.css;
// ...before overwriting the jQuery extension point
$.fn.css = function()
{
// original behavior - use function.apply to preserve context
var ret = oldcss.apply(this, arguments);
// stuff I will be extending
// that doesn't affect/change
// the way .css() works
// preserve return value (probably the jQuery object...)
return ret;
};
})(jQuery);
Peter Errikson write a very usfull code in extending jQuery with two new events, onShow and onHide with jsfiddle code sample...
i suggesst read that article..its looks very nice :)
链接地址: http://www.djcxy.com/p/80962.html下一篇: 扩展现有的jQuery函数