美文网首页
获取样式

获取样式

作者: 六月太阳花 | 来源:发表于2017-02-06 09:53 被阅读0次

    获取样式
    obj.style.width 只能取到行间样式
    getComputedStyle: 计算后的(生效的)样式
    用法:
    getComputedStyle(obj,false).样式 ;
    --false: 伪类 伪元素
    兼容性:
    Chrome FF IE9+
    不兼容:ie8 ie7 ..以下
    obj.currentStyle.样式;
    兼容性:IE 整个系列
    不兼容 Chrome FF ---> undefined

                function getStyle(obj,name){ 
                    if (obj.currentStyle){//ie
                        return obj.currentStyle[name];
                    }else{
                        return getComputedStyle(obj,false)[name];
                    }
                }
    

    相关文章

      网友评论

          本文标题:获取样式

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