码迷,mamicode.com
首页 > 编程语言 > 详细

javascript操作CSS样式表

时间:2014-10-15 12:17:36      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   java   sp   div   

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html>
 3  <head>
 4   <meta charset="UTF-8" />
 5   <!--meta http-equiv="x-ua-compatible"content="ie=7"/--> 
 6   <title>css</title>
 7   <style type="text/css">
 8       #div0{
 9          width:100px;
10          height:100px;
11          background:red;
12       }
13   </style>
14   
15   <script type="text/javascript">
16       window.onload = function(){
17          var oDiv = document.getElementById("div0");
18 
19          var sheet = document.styleSheets[0];
20          var ruls = sheet.cssRules || sheet.rules;
21          var rule = ruls[0];
22          alert(rule.selectorText);
23          alert(rule.style.cssText);
24          alert(rule.style.background);
25 
26          if(document.all)
27          {
28             sheet.addRule("#div0","color:blue",0);
29          }else
30          {
31             sheet.insertRule("#div0{color:orange}",0)
32          }
33          
34 
35       }
36   </script>
37  </head>
38  <body>
39     <div id="div0">DIV</div>
40  </body>
41 </html>

 

javascript操作CSS样式表

标签:style   blog   http   color   io   ar   java   sp   div   

原文地址:http://www.cnblogs.com/tuoyuan/p/4025894.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!