美文网首页
js中currentStyle和getComputedStyle

js中currentStyle和getComputedStyle

作者: 云烟成雨点 | 来源:发表于2018-08-28 19:19 被阅读0次

js中获取样式我了解到三种。一种是通过obj.offsetAttr来获取样式,通过这种方法来获取元素的宽高时,如果没有边框,可以正确获取,如果使用边框属性则会出现问题,为了解决这个问题,可以使用另一种方法,通过getComputedStyle属性来获取css样式(非行间)。还有一种是通style属性来获取css样式(行间)。

/*可以作为一段标准代码,理解并记忆(个人建议)*/  currentStyle  IE 兼容写法

 function      getStyle    (obj,attr){ 

 if(obj.currentStyle){

                return obj.currentStyle[attr];

            }else{

                return getComputedStyle(obj,false)[attr];

            } }

相关文章

网友评论

      本文标题:js中currentStyle和getComputedStyle

      本文链接:https://www.haomeiwen.com/subject/dogqwftx.html