中文字幕日韩一区二区_国产一区二区av_国产毛片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操作部分使用說明,轉載需保留來源!

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

主站蜘蛛池模板: 日韩欧美一区二区三区免费观看 | 国产精品亚洲片在线播放 | 国产一级一级国产 | 欧美视频成人 | 久草福利| 色综合国产 | 成人免费在线网 | 国产欧美精品一区二区三区 | 国产高清视频一区二区 | av性色| 欧美激情欧美激情在线五月 | 欧美精品影院 | 91在线视频免费观看 | 日韩精品在线观看一区二区三区 | 一区二区三区国产视频 | 一区二区三区四区在线视频 | 久久亚洲国产精品日日av夜夜 | 亚洲成人一区 | 黄网站免费在线看 | 国产日韩欧美 | 欧美一级观看 | 国产999精品久久久影片官网 | 亚洲www啪成人一区二区麻豆 | 久久综合一区 | 国产精品久久久久久妇女6080 | .国产精品成人自产拍在线观看6 | 国产超碰人人爽人人做人人爱 | 九九热在线视频免费观看 | 色综合色综合色综合 | 一区二区三区免费 | 狠狠干天天干 | 黄色一级免费看 | 伊人成人免费视频 | 国产你懂的在线观看 | 久久久欧洲 | 在线观看国产视频 | 国产亚洲精品久久情网 | 亚洲一区二区精品视频在线观看 | 青青草一区二区 | 91看片免费 | 高清一区二区三区 |