zoukankan      html  css  js  c++  java
  • DHTML &&CSS样式表

    (自己的见解,第一次写,请多多指教!)

    关于css分为3中方式:

    1.内联式 2.嵌入式 3.外联式

    关于这几种大家都是很明白的额(分别介绍下):

    代码:DESC(倒序)

    View Code
     1 <head>
     2 <style type="text/css">
     3 @import myStyle.css;
     4 </style>
     5 </head>
     6 <body>
     7 <div id="oDiv">请点击<a href="page.html">网站链接</a></div>
     8 <script type="text/javascript">
     9 var oStyleSheet=document.styleSheets[0]; // 获取style元素定义的样式表
    10 var oImport=oStyleSheet.imports[0];       // 获取其中第一个@import指令
    11 oRule = oImport.rules[0];                   // 获取样式表中的第一个规则
    12 alert(oRule.style.color);                   // 下面就是访问规则
    13 oRule.style.color = "green";
    14 oRule.style.fontSize = "13px";
    15 alert(oRule.style.color);
    16 </script>
    17 </body>
    View Code
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>DHTML && CSS</title>
    <style type="text/css">
    div{color:rgba(102,102,102,1);font-weight:bold;}
    p{ color:rgba(255,51,0,1);font-size:15px;}
    </style>
    </head>
    
    <body>
      <div id="fan">PLEASE<a href="#">LINK</a></div>
    <script type="text/javascript">
    var oStyleSheet=document.styleSheets[0]; 
    var oRule=oStyleSheet.rules[0];
    alert(oRule.style.color);     // 访问规则中定义的样式属性color
    oRule.style.color = "green";       // 改变规则中定义的样式属性color
    oRule.style.fontSize = "13px";    // 在规则中新增样式属性fontSize
    alert(oRule.style.color);           // 访问改变后的样式属性color
    </script>
    </body>
    </html>
    View Code
     1 <!doctype html>
     2 <html>
     3 <head>
     4  <meta charset="utf-8">
     5   <title>css</title>
     6 </head>
     7 <body>
     8  <div id="StyleSheet" style="color:"blue"; fontsize=20px;">PLEASE<a href="#">LINK</a></div>
     9 
    10  <script type="text/javascript">
    11   var oStyleSheet=document.getById("StyleSheet")
    12   alert(oStyleSheet.style.color);
    13   afan.style.color="green";
    14   afan.style.fontSize="15px";
    15   alert(afan.style.color);
    16  </script>
    17 </body>
    18 </html>
  • 相关阅读:
    换个格式输出整数
    c++入门构造函数
    接口继承与实现
    spring mvc 之@requestmapping
    RabbitMQ
    Socket通信原理
    TCP三次握手与四次挥手
    WIN 10家庭版没有Hyper-V
    aop 切面demo
    JVM之旅------jvm内存模型
  • 原文地址:https://www.cnblogs.com/fengyeyang/p/2796957.html
Copyright © 2011-2022 走看看