日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
jQuery1.6c新增的適配器

其實(shí)在jQuery1.5中已有這東西,cssHooks,或者更早之前的jQuery.event.special, 或者 Sizzle.selectors里面更多的對(duì)象。它們共同的特點(diǎn)是包含了許多相關(guān)的函數(shù),cssHooks是專門處理css屬性的獲取與設(shè)置,如IE的opacity,event.special用于裝載與卸載submit, change, focus ,mouseenter等特別事件與自定義事件, Sizzle.selectors里面的過(guò)濾器與候選集獲取器就更不用說(shuō)了。由于JS用對(duì)象做為表進(jìn)行查找是比if條句與switch語(yǔ)句快很多,加之,適配器這種模式對(duì)于擴(kuò)展新功能非常有利,因?yàn)閖Query1.6便把它發(fā)揚(yáng)光大了。

成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比龍華網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式龍華網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋龍華地區(qū)。費(fèi)用合理售后完善,十載實(shí)體公司更值得信賴。

在jQuery的attributes模塊(github是這樣分割的,但耦合這么高很難說(shuō)是模塊),共增加了三個(gè)這樣對(duì)象,valHooks,attrHooks, propHooks,分別對(duì)應(yīng)val,attr與prop這個(gè)三個(gè)方法。prop是新增的,表示jQuery決定區(qū)分屬性與特性的決心,但I(xiàn)E6/7還是無(wú)法區(qū)分它們,因此attr基本上涵蓋了prop的功能。

我們看一下它們各自的運(yùn)用吧!

 
 
  1. // jQuery.style 方法  
  2.       if ( value !== undefined ) {    
  3.         //=================略==============  
  4.         // If a hook was provided, use that value, otherwise just set the specified value    
  5.         if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value )) !== undefined ) {  
  6.            // Wrapped to prevent IE from throwing errors when 'invalid' values are provided  
  7.            // Fixes bug #5509  
  8.           try {  
  9.              style[ name ] = value;  
  10.            } catch(e) {}  
  11.          }  
  12.   
  13.       } else {  
  14.          // If a hook was provided get the non-computed value from there  
  15.          if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {  
  16.            return ret;  
  17.          } 
  18.         // Otherwise just get the value from the style object  
  19.         return style[ name ];  
  20.       } 
 
 
  1. // jQuery.fn.val 方法  
  2.       if ( !arguments.length ) {  
  3.         if ( elem ) {  
  4.           hooks = jQuery.valHooks[ elem.nodeName.toLowerCase() ] || jQuery.valHooks[ elem.type ];  
  5.           if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {  
  6.             return ret;  
  7.          }  
  8.            return (elem.value || "").replace(rreturn, "");  
  9.         }  
  10.         return undefined;  
  11.      }  
  12.      //===============略============   
  13.       hooks = jQuery.valHooks[ this.nodeName.toLowerCase() ] || jQuery.valHooks[ this.type ];  
  14.       // If set returns undefined, fall back to normal setting  
  15.       if ( !hooks || ("set" in hooks && hooks.set( this, val, "value" ) === undefined) ) {  
  16.         this.value = val;  
  17.       } 
 
 
  1. // jQuery.attr 方法  
  2.      hooks = jQuery.attrHooks[ name ] || ( jQuery.nodeName( elem, "form" ) && formHook );  
  3.       if ( value !== undefined ) {  
  4.         if ( value === null || (value === false && !rspecial.test( name )) ) {  
  5.           jQuery.removeAttr( elem, name );  
  6.           return undefined;  
  7.         } else if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value, name )) !== undefined ) {  
  8.           return ret;  
  9.         } else {  
  10.           // Set boolean attributes to the same name  
  11.          if ( value === true && !rspecial.test( name ) ) {  
  12.             value = name;  
  13.           }  
  14.          elem.setAttribute( name, "" + value );  
  15.           return value;  
  16.         }  
  17.       } else {  
  18.         if ( hooks && "get" in hooks && notxml ) {  
  19.           return hooks.get( elem, name );  
  20.         } else {  
  21.           ret = elem.getAttribute( name );  
  22.           // Non-existent attributes return null, we normalize to undefined  
  23.           return ret === null ? undefined : ret;  
  24.         }  
  25.       } 
 
 
  1. // jQuery.prop 方法  
  2.            hooks = jQuery.propHooks[ name ];  
  3.         if ( value !== undefined ) {  
  4.             if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {  
  5.                 return ret;  
  6.             } else {  
  7.                 return (elem[ name ] = value);  
  8.            }  
  9.         } else {  
  10.             if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== undefined ) {  
  11.                 return ret;  
  12.             } else {  
  13.                 return elem[ name ];  
  14.             }  
  15.         } 
 
 
  1. //jQuery.event.add  
  2.       if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {  
  3.      // Bind the global event handler to the element  
  4.         if ( elem.addEventListener ) {  
  5.           elem.addEventListener( type, eventHandle, false ); 
  6.         } else if ( elem.attachEvent ) {  
  7.           elem.attachEvent( "on" + type, eventHandle );  
  8.         }  
  9.       }  
  10. //jQuery.event.remove  
  11.       if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) {  
  12.        jQuery.removeEvent( elem, type, elemData.handle );  
  13.    } 

可以發(fā)現(xiàn)還是很有章法的。這些適配器就是用來(lái)處理一些特殊的屬性,樣式或事件。而這些屬性,樣式或事件,我們可以通過(guò)瀏覽器的特征嗅探,把相應(yīng)的解決方法添加到適配器中。有了這些適配器,jQuery就可以省去許多if else 判定,當(dāng)正式版發(fā)布時(shí),又可以高興地宣布這幾個(gè)方法快了多少百分比了!

可以發(fā)現(xiàn)還是很有章法的。這些適配器就是用來(lái)處理一些特殊的屬性,樣式或事件。而這些屬性,樣式或事件,我們可以通過(guò)瀏覽器的特征嗅探,把相應(yīng)的解決方法添加到適配器中。有了這些適配器,jQuery就可以省去許多if else 判定,當(dāng)正式版發(fā)布時(shí),又可以高興地宣布這幾個(gè)方法快了多少百分比了!

可以發(fā)現(xiàn)還是很有章法的。這些適配器就是用來(lái)處理一些特殊的屬性,樣式或事件。而這些屬性,樣式或事件,我們可以通過(guò)瀏覽器的特征嗅探,把相應(yīng)的解決方法添加到適配器中。有了這些適配器,jQuery就可以省去許多if else 判定.


當(dāng)前文章:jQuery1.6c新增的適配器
文章網(wǎng)址:http://www.dlmjj.cn/article/dpggopp.html