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

jQuery 中關于CSS操作部分使用說明

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

原代碼中關于CSS及className的操作部分節選如下:
復制代碼 代碼如下:
  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官方網站:http://jquery.com/
jQuery源碼下載:http://docs.jquery.com/Downloading_jQuery
jQuery API文檔:http://docs.jquery.com/Main_Page
jQuery 中國:http://jquery.org.cn/
VisualJQuery.com : http://visualjquery.com/

JavaScript技術jQuery 中關于CSS操作部分使用說明,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 欧美eee114| 99精品国产AV一区二区麻豆 | 亚洲AV久久无码精品九号软件 | 免费看成人毛片 | 久久精品电影久久电影大全 | 男人边吃奶边摸边做刺激情话 | 亚洲人视频在线观看 | 国产偷国产偷亚洲高清app | 樱桃视频影院在线播放 | 强姧伦久久久久久久久 | 欲奴第一季在线观看全集 | 91麻豆国产精品91久久久 | 在线观看视频国产 | 在线观看视频国产 | 蜜芽视频在线观看视频免费播放 | 成人毛片手机版免费看 | 亚洲视频精品在线观看 | 国产色精品久久人妻无码 | 色偷偷影院 | 亚洲AV精品无码成人 | 午夜免费啪视频观看视频 | 男同志在线观看 | 久久性色AV亚洲电影无码 | 国产精品日本无码久久一老A | 亚洲中文字幕永久在线 | 国产区免费在线观看 | 伊在香蕉国产在线视频 | 在线自拍亚洲视频欧美 | 久久婷婷五月综合色丁香 | 日本调教网站 | h片下载地址 | 久久频这里精品99香蕉久网址 | 久99久热只有精品国产99 | 黑人巨摘花破女处 | 免费特黄一区二区三区视频一 | 国产午夜小视频 | 2019在秋霞理论 | 偷拍久久国产视频免费 | 日本久久免费大片 | 国产在线精彩亚洲久久 | 在线看片福利无码网址 |