改变背景色的js代码

style.backgroundColor以前老弄错  毕竟css样式表里一般写

backgroud-color有点不习惯 

 

另外在表格里的行之间鼠标滑过的时候如果要改变背景色的话 如果单加有点麻烦毕竟要加很多行

css中是可以加js事件的 这样就可以在css中统一定义省去不少麻烦


比如有个简单的table

<table id="t1" >

<tr width="100 px"><td>hello</td></tr>

<tr width="100 px"><td>hello</td></tr> 

 </talbe>

那么就可以在样式表里面这样写 

<style type="text/css">

#t1 tr{

myex:expression(onmouseover=function(){this.style.backgroudColor="#000000";})

}

</style>

#d1{ background-color:#666666; width:100px; height:100px; myex:expression(onmouseover=function(){this.style.backgroundColor="#ff00ff"}); }

 

这里需要注意的是要加函数不可以直接写表达式 

如果写成onmouseover=this.style....则不会出现你想要的效果

如果直接是一个函数的话 就不用加function

比如onmouseover=this.blur;


Type text here

 

posted @ 2008-07-25 18:39  fool  阅读(1250)  评论(0编辑  收藏  举报