jquery extend 方法

来源:互联网 发布:php 字符串转义 编辑:程序博客网 时间:2024/05/17 02:06

1.扩展jQuery静态方法

$.extend({test:function(){alert('test函数')}})

用法: $.test()

2.合并多个对象.

//用法: jQuery.extend(obj1,obj2,obj3,..)var Css1={size: "10px",style: "oblique"}var Css2={size: "12px",style: "oblique",weight: "bolder"}$.jQuery.extend(Css1,Css2)//结果:Css1的size属性被覆盖,而且继承了Css2的weight属性// Css1 = {size: "12px",style: "oblique",weight: "bolder"}

3.深度镶套对象

// 以前的 .extend()      jQuery.extend(       { name: “John”, location: { city: “Boston” } },       { last: “Resig”, location: { state: “MA” } }      );     // 结果:       // => { name: “John”, last: “Resig”, location: { state: “MA” } } // 新的更深入的 .extend()     jQuery.extend( true,     { name: “John”, location: { city: “Boston” } },       { last: “Resig”, location: { state: “MA” } }    );    // 结果     // => { name: “John”, last: “Resig”,    //      location: { city: “Boston”, state: “MA” } } 


原创粉丝点击