沉睡森林@漂在北京

          本處文章除注明“轉載”外均為原創,轉載請注明出處。

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            152 隨筆 :: 4 文章 :: 114 評論 :: 0 Trackbacks

          jQuery.extend函數詳細用法
          最近在研究jQuery。把jQuery.extend擴展函數的用法記錄下來。

          1、擴展jQuery靜態方法.

          1$.extend({
          2test:function(){alert('test函數')}
          3})
          用法: $.test()


          2、合并多個對象.
          為jQuery.extend(css1,css2)為例,css1,css2個有一些屬性(法照樣會比處理,這里之講屬性).
          extend函數會把css2有而css2沒有的屬性加到css1中,如果css2的某個屬性與css1的某個屬性名稱享用,就會用css2的屬性去覆蓋css1的同名屬性。css1就是最后的整和對象。或者也可以用 :
          var newcss = jquery.extend(css1,css2)  newcss就是合并的新對象。
          var newcss = jquery.extend({},css1,css2) newcss就是合并的新對象.而且沒有破壞css1的結構。

          1//用法: jQuery.extend(obj1,obj2,obj3,..)
          2var Css1={size: "10px",style: "oblique"}
          3var Css2={size: "12px",style: "oblique",weight: "bolder"}
          4$.jQuery.extend(Css1,Css2)
          5//結果:Css1的size屬性被覆蓋,而且繼承了Css2的weight屬性
          6// Css1 = {size: "12px",style: "oblique",weight: "bolder"}
          7

          3。深度鑲套對象
          新的extend()允許你更深度的合并鑲套對象。下面的例子是一個很好的證明。
          1// 以前的 .extend()   
          2   jQuery.extend(   
          3     { name: “John”, location: { city: “Boston” } },   
          4     { last: “Resig”, location: { state: “MA” } }   
          5   );   
          6    // 結果:   
          7    // => { name: “John”, last: “Resig”, location: { state: “MA” } }
          8  // 新的更深入的 .extend()   
          9   jQuery.extend( true,   
          10   { name: “John”, location: { city: “Boston” } },   
          11     { last: “Resig”, location: { state: “MA” } }   
          12  );   
          13  // 結果   
          14   // => { name: “John”, last: “Resig”,   
          15  //      location: { city: “Boston”, state: “MA” } }  
          16

          本篇文章來源于PHP論壇 文章地址:http://bbs.php.cn/thread-33593-1-4.html

          posted on 2009-11-05 11:54 王總兵 閱讀(370) 評論(0)  編輯  收藏 所屬分類: OtherjQuery
          主站蜘蛛池模板: 济宁市| 红桥区| 邢台县| 遵化市| 新绛县| 沛县| 德昌县| 新竹县| 明光市| 丘北县| 万全县| 方正县| 鹿邑县| 石阡县| 六枝特区| 彰化县| 温宿县| 错那县| 榕江县| 弥勒县| 象州县| 镇远县| 鹤壁市| 永安市| 泉州市| 绥中县| 乌拉特前旗| 耒阳市| 新安县| 五寨县| 廉江市| 广丰县| 额敏县| 湖北省| 大同市| 凤山县| 高青县| 财经| 漳州市| 隆安县| 堆龙德庆县|