获取css属性

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
 5     <title></title>
 6     <style type="text/css">
 7         div.box{
 8             background-color:blue;
 9             width:100px;
10             height:200px;
11         }
12     </style>
13     <script type="text/javascript" src="test49.js"></script>
14 </head>
15 <body>
16     
17 </body>
18 </html>
 1 var sheet = document.styleSheets[0];
 2 var rules = sheet.cssRules || sheet.rules;
 3 var rule = rules[0];
 4 console.log(rule.selectorText);
 5 console.log(rule.style.cssText);
 6 console.log(rule.style.backgroundColor);
 7 console.log(rule.style.width);
 8 console.log(rule.style.height);
 9 
10 rule.style.backgroundColor = "red";
11 console.log(rule.style.backgroundColor);
posted @ 2012-05-15 13:07  小猩猩君  阅读(155)  评论(0编辑  收藏  举报