如何改变.redText #pid 里面的CSS属性?

yfgcq 2007-10-24 10:25:24
<STYLE TYPE="text/css">
.redText {color: red;}
#pid {color: red;}
</STYLE>

<P id="redText" CLASS="redText">11</p>
<P id="pid">22</p>

<script language="javascript" type="text/javascript">
function getpid()
{
var redTextobj=document.getElementById("redText");
var pidobj=document.getElementById("pid");
alert(redTextobj.style.color);
alert(pidobj.style.color);
怎么改变redTextobj、pidobj这个两对象现在的color属性?

}
getpid()
</script>
...全文
95 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
CutBug 2007-10-24
  • 打赏
  • 举报
回复
<STYLE TYPE="text/css" > 
.redText {color: red;}
#pid {color: red;}
</STYLE >
<P id="redText" CLASS="redText" >11 </p >
<P id="pid" >22 </p >
<input type="button" onclick="test()" value=" test " />
<script language="javascript" type="text/javascript" >
function test()
{
var ss = document.styleSheets[0];
var rules = ss.rules?ss.rules:ss.cssRules
for(var i=0;i<rules.length;i++)
{
if(rules[i].selectorText=="#pid")
{
rules[i].style.color="yellow";
}
}


}
</script>
<html> <head> <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta http-equiv="refresh" content="15; url=http://www.onlinedown.net/"> <title>华军软件园下载文件说明</title> <style type="text/css"> body {background-image: url(http://www.onlinedown.net/newhuagg/bj2.gif); background-repeat: repeat-x; background-color: #B2E8F5; } input{-webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box;} .hj {border: 1px none #55A0E6; line-height: 20px; color: #0000; text-decoration: none; line-height: 20px; color: #000000; font-weight: normal; font-size: 14px; } .zi {font-size: 20px; color: #000;height: 50px;line-height: 50px; text-decoration: none; font-weight: 600; } .zi span{color:red;} </style> <link rel="stylesheet" type="text/css" href="http://src.onlinedown.net/Public/css/newstyle/reset.css"> <link rel="stylesheet" type="text/css" href="http://src.onlinedown.net/Public/css/newstyle/headfoot.css"> [removed] var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?1057fce5375b76705b65338cc0397720"; var s = document.getElementsByTagName("script")[0]; s[removed].insertBefore(hm, s); })(); [removed] </head> <body> 找软件用软件,到华军软件园! 软件发布 <!-- 搜索 -->

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧