一道很简单猥琐的样式问题

yanggao19900905 2011-02-09 02:23:55
定义下面的CSS
.red *{color:#f00}
.red {color:#f00}

用JS实现,代码如下
tr.className='red';实现效果没问题

但是td.className='red';没有任何反应!
td中包含一个div标签,div里面有一段话!

请教为什么会出现这样的情况?
...全文
141 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanggao19900905 2011-02-10
  • 打赏
  • 举报
回复
已经解决了,是域的问题!

当前table是放在一个单独的html中的(ifram)嵌套进来的
只写了
.excelTable tr.red td div{color:#f00;}

应该加上
.excelTable td.red *{color:#f00}
.excelTable td.red {color:#f00}

yanggao19900905 2011-02-10
  • 打赏
  • 举报
回复
我是IE8
还是解决不了!
xmlife 2011-02-10
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 yanggao19900905 的回复:]

引用 9 楼 xmlife 的回复:
在JS脚本中同时写上
document.getElementById('123').setAttribute("class", "red"); //for firefox
document.getElementById('123').setAttribute("className", "red"); //for ie

貌似不是这个原因哦!
[/Quote]
在IE6和FireFox测试可以
yanggao19900905 2011-02-10
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zhenhuixia 的回复:]
id就是123吗,不要以数字开头命名CSS伪类名
[/Quote]
不要以数字开头命名CSS伪类名?
yanggao19900905 2011-02-10
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 xmlife 的回复:]
在JS脚本中同时写上
document.getElementById('123').setAttribute("class", "red"); //for firefox
document.getElementById('123').setAttribute("className", "red"); //for ie
[/Quote]
貌似不是这个原因哦!
xmlife 2011-02-09
  • 打赏
  • 举报
回复
在JS脚本中同时写上
document.getElementById('123').setAttribute("class", "red"); //for firefox
document.getElementById('123').setAttribute("className", "red"); //for ie
xmlife 2011-02-09
  • 打赏
  • 举报
回复
====是js兼容性问题====

function SetWithDraw()
{
document.getElementById('123').setAttribute("class", "red"); //for firefox
document.getElementById('123').setAttribute("className", "red"); //for ie
}

zhenhuixia 2011-02-09
  • 打赏
  • 举报
回复
id就是123吗,不要以数字开头命名CSS伪类名
yanggao19900905 2011-02-09
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 cj205 的回复:]
css没问题
js理论上也没问题
检查下你的所有代码中有多少个id叫123的元素
[/Quote]
只有一个!
Mr-Jee 2011-02-09
  • 打赏
  • 举报
回复
css没问题
js理论上也没问题
检查下你的所有代码中有多少个id叫123的元素
yanggao19900905 2011-02-09
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 cj205 的回复:]
代码有问题
发出来我看看
[/Quote]
function SetWithDraw()
{
document.getElementById('123').setAttribute("class", "red");
}

.red *{color:#f00}
.red {color:#f00}

我怀疑是CSS没写好! 把123换成tr的ID就没问题!

123中包含一个DIV
Mr-Jee 2011-02-09
  • 打赏
  • 举报
回复
代码有问题
发出来我看看
yanggao19900905 2011-02-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 tcwsyt 的回复:]
td.setAttribute("className", "red");
td.setAttribute("class", "red");


用这个呢。
[/Quote]

还是不行!
灬上海爽爷 2011-02-09
  • 打赏
  • 举报
回复
td.setAttribute("className", "red");
td.setAttribute("class", "red");


用这个呢。

61,124

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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