本文转自:http://www.cnblogs.com/know/archive/2011/03/13/1982839.html
开发jquery插件有两种方法:
jQuery.extend(object)——对jQuery类扩展.为jQuery类添加新的方法,新方法可以理解为静态方法。例如:
$.extend({
add:function(a,b){return a+b;}
});
jQuery.fn.extend(object);给jQuery对象添加方法,是给jQuery.prototype进得扩展,可以理解为实例上的方法,
通常我们使用 $("#input1"),其实是得到一个jQuery类的实例。例如下面的扩展jquery实例的方法:alertWhileClick,就是通过$("#input1"),得到的jquery类的实例,从而实例可以使用这个扩展方法:
$.fn.extend({
alertWhileClick:function(){
$(this).click(function(){
alert($(this).val());
});
}
});
$("#input1").alertWhileClick(); //页面上为:<input id="input1" type="text"/>