jQuery.fn.extend 与 jQuery.extend 用法

 1.jQuery.fn.extend 是对jQuery方法进行扩展

demo: jquery 本身并不提供 jQuery.color() 这个方法,如果我们需要对jQuery本身提供的方法进行扩展,则我们就需要是用jQuery.fn.extend

复制代码
jQuery.fn.extend({
color:function(val)
{
if(val==undefined){

return $(this).css("color");
}else{

return $(this).css("color",val);
}
}
})



$(this).color("red");//对jquery对象进行颜色设置
alert($(this).color());//获取jquery对象的颜色,并用对话框弹出
复制代码

2.jQuery.extend 对jQuery对象的扩展,可以理解为静态方法,不需要实例jQuery就可以使用

jQuery.extend( {
myshow:function(a,b)
{
return a+b;
}
})

调用:alert($.add(3, 4)); 

原文地址:https://www.cnblogs.com/lvfeilong/p/hgfhgfh.html