沉睡森林@漂在北京

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

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

          jQuery.extend函數(shù)詳細(xì)用法
          最近在研究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 王總兵 閱讀(365) 評論(0)  編輯  收藏 所屬分類: OtherjQuery
          主站蜘蛛池模板: 黎平县| 抚松县| 阿勒泰市| 安义县| 深泽县| 平湖市| 江津市| 敖汉旗| 宁波市| 邵东县| 临城县| 广丰县| 兴文县| 邹城市| 布尔津县| 墨玉县| 宜昌市| 太康县| 砀山县| 黔南| 仁布县| 铅山县| 汽车| 寻乌县| 乌鲁木齐市| 久治县| 通山县| 丁青县| 东乌珠穆沁旗| 高陵县| 阳原县| 潍坊市| 长葛市| 芦山县| 德昌县| 惠水县| 陆河县| 防城港市| 康乐县| 海晏县| 台前县|