javascript操作css屬性

來源:互聯網
上載者:User

 今天因需要用到js擷取css屬性,網上搜了半天都不合適的。有一下幾種方法

 代碼如下:var getstyle = function(elementID,attribute){ obj = document.getElementById(elementID);// 前面是IE後面是html的標準 return obj.currentStyle ? obj.currentStyle[attribute] : document.defaultView.getComputedStyle(obj, false)[attribute];}  還有一種可以擷取寫在html中的style屬性的  代碼如下:document.getElementById("elementId").style.paddingLeft; 
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.