天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

jQuery 中關(guān)于CSS操作部分使用說(shuō)明

剛剛看了下jQuery的源代碼,其中關(guān)于CSS及className的操作思想確實(shí)很不錯(cuò),值得借鑒。
其中關(guān)于jQuery.className.has的定義部分,是用的正則來(lái)實(shí)現(xiàn)的,其實(shí)此處直接利用Javascript中String對(duì)象的indexOf方法來(lái)作處理的話(huà),比用正則效率會(huì)更些,因此復(fù)制代碼 代碼如下:
jQuery.className.has的定義可以改進(jìn)成: 
    has: function( t, c ) { 
      t = t.className || t; 
      t = " " + t + " "; 
      c = " " + c + " "; 
      return t.indexOf(c)>-1; 
    } 

原代碼中關(guān)于CSS及className的操作部分節(jié)選如下:
復(fù)制代碼 代碼如下:
  className: { 
    // internal only, use addClass("class") 
    add: function( elem, c ){ 
      jQuery.each( c.split(//s+/), function(i, cur){ 
        if ( !jQuery.className.has( elem.className, cur ) ) 
          elem.className += ( elem.className ? " " : "" ) + cur; 
      }); 
    }, 

    // internal only, use removeClass("class") 
    remove: function( elem, c ){ 
      elem.className = c ? 
        jQuery.grep( elem.className.split(//s+/), function(cur){ 
          return !jQuery.className.has( c, cur );   
        }).join(" ") : ""; 
    }, 

    // internal only, use is(".class") 
    has: function( t, c ) { 
      t = t.className || t; 
      // escape regex characters 
      c = c.replace(/([/.///+/*/?/[/^/]/$/(/)/{/}/=/!/</>/|/:])/g, "http://$1"); 
      return t && new RegExp("(^|//s)" + c + "(//s|$)").test( t ); 
    } 
  }, 
  swap: function(e,o,f) { 
    for ( var i in o ) { 
      e.style["old"+i] = e.style[i]; 
      e.style[i] = o[i]; 
    } 
    f.apply( e, [] ); 
    for ( var i in o ) 
      e.style[i] = e.style["old"+i]; 
  }, 

  css: function(e,p) { 
    if ( p == "height" || p == "width" ) { 
      var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"]; 

      jQuery.each( d, function(){ 
        old["padding" + this] = 0; 
        old["border" + this + "Width"] = 0; 
      }); 

      jQuery.swap( e, old, function() { 
        if (jQuery.css(e,"display") != "none") { 
          oHeight = e.offsetHeight; 
          oWidth = e.offsetWidth; 
        } else { 
          e = jQuery(e.cloneNode(true)) 
            .find(":radio").removeAttr("checked").end() 
            .css({ 
              visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0" 
            }).appendTo(e.parentNode)[0]; 

          var parPos = jQuery.css(e.parentNode,"position"); 
          if ( parPos == "" || parPos == "static" ) 
            e.parentNode.style.position = "relative"; 

          oHeight = e.clientHeight; 
          oWidth = e.clientWidth; 

          if ( parPos == "" || parPos == "static" ) 
            e.parentNode.style.position = "static"; 

          e.parentNode.removeChild(e); 
        } 
      }); 

      return p == "height" ? oHeight : oWidth; 
    } 

    return jQuery.curCSS( e, p ); 
  }, 

  curCSS: function(elem, prop, force) { 
    var ret; 

    if (prop == "opacity" && jQuery.browser.msie) 
      return jQuery.attr(elem.style, "opacity"); 

    if (prop == "float" || prop == "cssFloat") 
     prop = jQuery.browser.msie ? "styleFloat" : "cssFloat"; 

    if (!force && elem.style[prop]) 
      ret = elem.style[prop]; 

    else if (document.defaultView && document.defaultView.getComputedStyle) { 

      if (prop == "cssFloat" || prop == "styleFloat") 
        prop = "float"; 

      prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase(); 
      var cur = document.defaultView.getComputedStyle(elem, null); 

      if ( cur ) 
        ret = cur.getPropertyValue(prop); 
      else if ( prop == "display" ) 
        ret = "none"; 
      else 
        jQuery.swap(elem, { display: "block" }, function() { 
         var c = document.defaultView.getComputedStyle(this, ""); 
         ret = c && c.getPropertyValue(prop) || ""; 
        }); 

    } else if (elem.currentStyle) { 

      var newProp = prop.replace(//-(/w)/g,function(m,c){return c.toUpperCase();}); 
      ret = elem.currentStyle[prop] || elem.currentStyle[newProp]; 

    } 

    return ret; 
  }, 

附錄:
jQuery官方網(wǎng)站:http://jquery.com/
jQuery源碼下載:http://docs.jquery.com/Downloading_jQuery
jQuery API文檔:http://docs.jquery.com/Main_Page
jQuery 中國(guó):http://jquery.org.cn/
VisualJQuery.com : http://visualjquery.com/

JavaScript技術(shù)jQuery 中關(guān)于CSS操作部分使用說(shuō)明,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 亚洲国产日韩欧美高清片a 亚洲国产日韩a精品乱码 | caoporm国产精品视频免费 | 国精产品一区一区三区有限公司 | 床上色APP下载免费版 | 俄罗斯6一9泑女网站 | 97人人看碰人免费公开视频 | 国产女合集小岁9三部 | 青青精品视频国产 | 快播av种子大全 | 果冻传媒视频在线观看完整版免费 | 亚洲中文字幕乱倫在线 | 欧美亚洲国产手机在线有码 | 亚洲精品伊人久久久久 | 最新高清无码专区在线视频 | 天天爽夜夜爽 | CHINESE老阿姨免费视频 | 菠萝菠萝蜜在线观看视频 | 伊人亚洲AV久久无码精品 | 丰满少妇67194视频 | 口内射精颜射极品合集 | 免费麻豆国产黄网站在线观看 | 中文字幕在线视频观看 | 龙岩综合频道 | 国产精品第1页在线观看 | 国产精品人妻无码久久久2022 | 成人毛片手机版免费看 | 色拍拍噜噜噜啦啦新网站 | 饥渴的40岁熟妇完整版在线 | 99久久国产综合精品网成人影院 | 美女被撕开胸罩狂揉大乳 | 中国农村真实bbwbbwbbw | 擼擼擼麻豆密臀AV | 国产乱辈通伦影片在线播放亚洲 | 白银谷在线观看 | 免费看国产精品麻豆 | 成人精品视频在线 | 国产成人综合在线 | 国产真实夫妇交换视频 | 天天狠狠色综合图片区 | 国产精品99久久久久久AV | 儿子日母亲B好爽 |