获取非行间样式函数

<script type="text/javascript">
    window.onload = function() {
        var som = document.getElementsByTagName('td')[0];
        function getStyle(obj, attr,value) {
            if(!value) {
                if(obj.currentStyle) {
                return obj.currentStyle[attr];
                } else {
                    return    window.getComputedStyle(obj,false)[obj,attr];
                }
            }else{
                obj.style[attr] = value
            }

        }
        console.log( getStyle(som,'font-size') );
        console.log( getStyle(som,'border') );
        console.log( getStyle(som,'color') );
    }
</script>

 

 

posted @ 2018-06-13 10:25  adongP  阅读(247)  评论(0编辑  收藏  举报