沉睡森林@漂在北京

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

            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的結構。

          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 王總兵 閱讀(372) 評論(0)  編輯  收藏 所屬分類: OtherjQuery
          主站蜘蛛池模板: 沙河市| 北川| 定州市| 通辽市| 绥滨县| 汕尾市| 甘德县| 永新县| 福建省| 邵武市| 汕头市| 邻水| 新丰县| 正阳县| 东辽县| 长海县| 区。| 彰化县| 商丘市| 社旗县| 温州市| 聂拉木县| 兴安县| 顺义区| 油尖旺区| 澄迈县| 彩票| 揭西县| 前郭尔| 白山市| 开封县| 游戏| 盖州市| 南昌市| 南部县| 信宜市| 常德市| 洛南县| 临夏市| 凭祥市| 荔浦县|