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>

转载于:https://www.cnblogs.com/fengyeyang/archive/2012/12/01/2796957.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值