javascript簡單實現(xiàn)表格行間隔顯示顏色并高亮顯示
更新時間:2013年11月29日 15:37:48 作者:
表格行間隔顯示顏色并實現(xiàn)高亮顯示,這種效果大家都有見到過吧,下面就為大家詳細介紹下,需要的朋友可不要錯過
復制代碼 代碼如下:
<script type="text/javascript">
var name; //存儲tr對象的類名,當鼠標移開時進行恢復
function trcolor(){ //表格行顏色間隔顯示
var tabNode = document.getElementsByTagName("table")[0];
var trNodes = tabNode.rows;
for(var x=1;x<trNodes.length;x++){
if(x%2 == 1)
trNodes[x].className = "one" ;
else
trNodes[x].className = "two" ;
trNodes[x].onmouseover = function(){ //高亮顯示
name = this.className;
this.className = "over";
}
trNodes[x].onmouseout = function(){ //tr對象添加onmouseout事件屬性
this.className = name ;
}
}
}
window.onload = trcolor ;
</script>
<style type="text/css">
table{ width:60%; border:solid 1px #0066FF;}
table td {border:solid 1px #0099ff;}
a{ text-decoration: none;}
.one{background-color: red;}
.two{background-color: blue;}
.over{background-color: yellow;}
</style>
</head>
<body>
<table>
<tr>
<td>姓名</td><td>年齡</td><td>地址</td>
</tr>
<tr>
<td>張三</td><td>23</td><td>北京</td>
</tr>
<tr>
<td>李四</td><td>25</td><td>上海</td>
</tr>
<tr>
<td>王五</td><td>15</td><td>廣州</td>
</tr>
<tr>
<td>唐總</td><td>20</td><td>長沙</td>
</tr>
</table>
</body>
相關文章
js扁平數(shù)組和樹結構相互轉(zhuǎn)換處理方法
這篇文章主要給大家介紹了關于js扁平數(shù)組和樹結構相互轉(zhuǎn)換處理方法的相關資料,之前面試有遇到過這個問題,面試官問如何把一個數(shù)組數(shù)據(jù)扁平,然后轉(zhuǎn)化為Tree結構數(shù)據(jù),工作中剛好也用到了,所以總結下,需要的朋友可以參考下2023-07-07