首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

获样片式中的属性值

2012-10-24 
获取样式中的属性值!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//ENhtmlheadtitle

获取样式中的属性值
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
  <head> 
    <title>b.html</title>     
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
    <meta http-equiv="description" content="this is my page"> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
    <style type="text/css"> 
        #d2 {  
            width:400px;  
            height:200px;  
            border:5px solid gray;  
            padding:5px;  
        }  
    </style>      
    <script> 
        window.onload=function(){  
              
            //2、使用嵌入、链入或引入样式表(非内联样式)  
              
            //ie:通过currentStyle           
            alert(document.getElementById('d2').currentStyle.width);//400px ie  
              
            //ff,safari,opera,chrome:通过window.getComputedStyle  
            var el=document.getElementById('d2');  
            alert(window.getComputedStyle(el,null).style.width);//400px safari,opera,chrome  
        }  
    </script> 
  </head> 
    
  <body>        
        <div id="d2"></div> 
  </body> 
</html> 

热点排行
Bad Request.