javascript中className 有作用,而style 怎么改才能用?

来源:百度知道 编辑:UC知道 时间:2024/05/25 20:45:25
table1.rows(2).className = "t3";
table1.rows(3).style = "background-color:#ccffee;";
第一句起作用,第二句是不是也可以改一两个字母就能用了?
原代码为:
<style>
.t3 {background-color:#ccffee;}
</style>

<table id="table1">
<tr><td>aaaaaaaaaaa</td></tr>
<tr><td>bbbbbbbbbbb</td></tr>
<tr><td>aaaaaaaaaaa</td></tr>
<tr><td>bbbbbbbbbbb</td></tr>
<tr><td>aaaaaaaaaaa</td></tr>
<tr><td>bbbbbbbbbbb</td></tr>

</table>

<script>
table1.rows(2).className = "t3";
table1.rows(3).style = "background-color:#ccffee;";
</script>

table1.rows(3).style = "background-color:#ccffee;";
修改为:
table1.rows(3).style.cssText = "background-color:#ccffee;";

二楼的写法是比较流行的,但是一楼的写法也是正确的,我在ie7下测试通过,ff还没有测试。

这样看来用style.cssText更具有通用性,不像第二种写法,每次还要考虑把style中的小横线替换成其后面的字母的大写。

不错不错,又和老大[阳光上的桥]学到一招。

table1.rows(3).style.backgroundColor= "#ccffee";
这个是常见的写法,楼主的写法是错误的。

刚试了下,FF下也可以