一、jquery添加静态方法
$.extend({
m1:function(){},
m2:function(){}
});
方法调用:$.m1();
二、jquery对象添加方法
1、 $.fn.extend({
m1:function(){},
m2:function(){}
});
2、$.fn.m1=function(){
alert(1);
}
方法调用:$("input").m1();
三、jquery合并多个对象
用法: jQuery.extend(obj1,obj2,obj3,..)
var Css1={size: “10px”,style: “oblique”}
var Css2={size: “12px”,style: “oblique”,weight: “bolder”}
var result=$.jQuery.extend(Css1,Css2)
结果:Css1的size属性被覆盖,而且继承了Css2的weight属性
Css1 = {size: “12px”,style: “oblique”,weight: “bolder”}
result==Css1;
四、jquery深度嵌套对象
$.extend(boolean,dest,src1,src2…), 深度镶套对象
第一个boolean类型的参数决定是否深度镶套
1、以前的 .extend()
jQuery.extend(
{ name: “John”, location: { city: “Boston” } },
{ last: “Resig”, location: { state: “MA” } }
);
结果: { name: “John”, last: “Resig”, location: { state: “MA” } }
2、新的extend()允许你更深度的合并镶套对象
jQuery.extend( true,
{ name: “John”, location: { city: “Boston” } },
{ last: “Resig”, location: { state: “MA” } }
);
结果 : { name: “John”, last: “Resig”, location: { city: “Boston”, state: “MA” } }