沉睡森林@漂在北京

          本處文章除注明“轉(zhuǎn)載”外均為原創(chuàng),轉(zhuǎn)載請注明出處。

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

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

          1、擴展jQuery靜態(tài)方法.

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


          2、合并多個對象.
          為jQuery.extend(css1,css2)為例,css1,css2個有一些屬性(法照樣會比處理,這里之講屬性).
          extend函數(shù)會把css2有而css2沒有的屬性加到css1中,如果css2的某個屬性與css1的某個屬性名稱享用,就會用css2的屬性去覆蓋css1的同名屬性。css1就是最后的整和對象?;蛘咭部梢杂?:
          var newcss = jquery.extend(css1,css2)  newcss就是合并的新對象。
          var newcss = jquery.extend({},css1,css2) newcss就是合并的新對象.而且沒有破壞css1的結(jié)構(gòu)。

          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//結(jié)果: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    // 結(jié)果:   
          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  // 結(jié)果   
          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 王總兵 閱讀(372) 評論(0)  編輯  收藏 所屬分類: OtherjQuery
          主站蜘蛛池模板: 班玛县| 年辖:市辖区| 敦煌市| 南宁市| 新泰市| 阜城县| 平湖市| 仪陇县| 阿坝| 宁阳县| 阳朔县| 门头沟区| 泉州市| 千阳县| 类乌齐县| 嫩江县| 乌海市| 锡林浩特市| 吴江市| 饶阳县| 会宁县| 久治县| 古浪县| 芷江| 内乡县| 西乌珠穆沁旗| 芮城县| 嵊泗县| 航空| 临朐县| 云林县| 阜宁县| 正定县| 宣恩县| 布尔津县| 开化县| 渑池县| 巴青县| 小金县| 连山| 德令哈市|