zoukankan      html  css  js  c++  java
  • JS获取CSS属性值

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <title> JS获取CSS属性 </title>
      <style type="text/css">
    	#f{background-color:#FF0000;}
      </style>
     </head>
    
     <body>
      <div id="f" style="200px; height:200px;"></div>
    
      <script type="text/javascript">
    	var o = document.getElementById('f');
    	document.write(o.style.width + '<br>'); // 200px
    	document.write(o.style.backgroundColor + '<br>'); // 空白
    
    	function getDefaultStyle(obj,attribute){
    		return obj.currentStyle?obj.currentStyle[attribute] : document.defaultView.getComputedStyle(obj,false)[attribute];   
    	}
    	document.write(getDefaultStyle(o, 'width') + '<br>'); // 200px
    	document.write(getDefaultStyle(o, 'backgroundColor')); // #FF0000
      </script>
     
     </body>
    
    </html>


    JS獲取CSS屬性方法:

    	function getDefaultStyle(obj,attribute){
    		return obj.currentStyle?obj.currentStyle[attribute] : document.defaultView.getComputedStyle(obj,false)[attribute];   
    	}


  • 相关阅读:
    [HNOI2004]L语言
    [TJOI2018]异或
    如何定位低效SQL?
    索引失效的情况有哪些?
    trace的作用?
    show profile的作用?
    索引的使用原则
    MySQL主从复制的步骤
    什么是聚簇索引
    什么是全文索引?
  • 原文地址:https://www.cnblogs.com/fdipzone/p/3715154.html
Copyright © 2011-2022 走看看