D-10-样式读取1

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            #box{
                width:200px;
                height:200px;
                background:#333333;
                font-size:22px;
            }
        </style>
        <script>
            window.onload = function(){
                
                  function  read(box,name){
                    //获取box
//                  var aaa= name;
                        //if(window.getComputedStyle){
                        //   sty =window.getComputedStyle(obj,null)[name]
                                //ie8以下浏览器
                             
                        //}else{
                        //  sty = obj.currentStyle[name]
                            
                        //}
//                  var box = document.getElementById(box);
//                  var sty = box.currentStyle.width;
                    var sty;
                    if(window.getComputedStyle){
                        sty = window.getComputedStyle(box,null)[name];
                    }else{
                        sty = box.currentStyle[name];
                    }
                    
                    return sty;                 
                }
                  //获取按钮
                var btn = document.getElementById("btn");           
                btn.onclick = function(){                   
                    console.log(read(box,"fontSize"))                   
                }               
            }
        </script>
    </head>
    <body>
        <button id="btn">点击REDSA</button>
        <div id = "box">
            
        </div>
        
    </body>
</html>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容