zoukankan      html  css  js  c++  java
  • 取制定元素的最终样式

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>test</title>
    <link rel="stylesheet" type="text/css" href="css.css">
    </head>
    <body>
        <div class="head">我的天空</div>
        <div>
        <table class="table">
            <tr>
                <td>
                    我的天空
                </td>
                <td>
                    我的天空
                </td>
                <td>
                    我的天空
                </td>
                <td>
                    我的天空
                </td>
                <td>
                    我的天空
                </td>
                <td>
                    我的天空
                </td>
            </tr>
        </table>
    </div>
        
    </body>
    </html>
    
    <script>
    
    function Toword(obj,arr){
        this.obj=obj;
        this.arr=arr;
        this.init(this.obj,this.arr);
    }
    
    Toword.prototype.getcss=function(obj,attr){
        return obj.currentStyle||getComputedStyle(obj,false)[attr];
    }
    Toword.prototype.init=function(){
        if(this.obj.length){
            for (var j = 0; j < this.obj.length; j++) {
                for (var i = 0; i < this.arr.length; i++) {
                    this.obj[j].style[this.arr[i]]=this.getcss(this.obj[j],this.arr[i]);
                }
            }
        }else{
                for (var i = 0; i < this.arr.length; i++) {
                    this.obj.style[this.arr[i]]=this.getcss(this.obj,this.arr[i]);
                }
        }
    }
    
    var oDiv=document.querySelector(".head");
    var aTd=document.querySelectorAll("td");
    var oTable=document.querySelector("table");
    new Toword(oTable,["width","borderCollapse"])
    new Toword(oDiv,["fontSize","backgroundColor","borderLeftWidth","borderLeftColor","borderLeftStyle","borderRightWidth","borderRightColor","borderRightStyle","borderBottomWidth","borderBottomColor","borderBottomStyle","borderTopWidth","borderTopColor","borderTopStyle"])
    new Toword(aTd,["fontSize","borderLeftWidth","borderLeftColor","borderLeftStyle","borderRightWidth","borderRightColor","borderRightStyle","borderBottomWidth","borderBottomColor","borderBottomStyle","borderTopWidth","borderTopColor","borderTopStyle","lineHeight","paddingLeft","paddingRight","paddingBottom","paddingTop"])
    
        
    </script>
  • 相关阅读:
    [HNOI2002]营业额统计
    HDU 1374
    HDU 3345
    HDU 2089
    Graham扫描法
    Codeforces 1144D Deduction Queries 并查集
    Codeforces 916E Jamie and Tree 线段树
    Codeforces 1167F Scalar Queries 树状数组
    Codeforces 1167E Range Deleting
    Codeforces 749E Inversions After Shuffle 树状数组 + 数学期望
  • 原文地址:https://www.cnblogs.com/busicu/p/4274011.html
Copyright © 2011-2022 走看看