沉睡森林@漂在北京

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

            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
          主站蜘蛛池模板: 木里| 九江市| 奉化市| 西乌| 航空| 广州市| 无为县| 宜章县| 巍山| 盐亭县| 从江县| 伽师县| 武乡县| 五河县| 安达市| 天镇县| 法库县| 石台县| 阜城县| 廊坊市| 那曲县| 屏南县| 大同市| 犍为县| 新建县| 宁强县| 醴陵市| 阿克陶县| 天全县| 朝阳市| 屏边| 松原市| 忻城县| 贡嘎县| 伊通| 宝山区| 抚顺县| 鸡西市| 昭觉县| 洛浦县| 丹凤县|