表格隔行变色效果,鼠标悬浮高亮显示
Posted summer0319
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了表格隔行变色效果,鼠标悬浮高亮显示相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
* {
margin: 0;
padding: 0;
}
table {
margin: 150px auto;
width: 500px;
border: 1px solid #000;
}
tr {
height: 40px;
}
td {
border: 1px solid #000;
line-height: 40px;
text-align: center;
}
</style>
<script>
window.onload = function () {
var tbody = document.getElementsByTagName("tbody")[0];
var trArr = tbody.getElementsByTagName("tr");
for(var i=0;i<trArr.length;i++){
if(i%2===0){
trArr[i].style.backgroundColor = "#BEBEBE";
}else{
trArr[i].style.backgroundColor = "#D0B8AD"
}
var color = "";
trArr[i].onmouseover = function () {
color = this.style.backgroundColor;
this.style.backgroundColor = "#76B481";
}
trArr[i].onmouseout = function () {
this.style.backgroundColor = color;
}
}
}
</script>
</head>
<body>
<table>
<caption>表格一:XXXXXXXX</caption>
<thead>
<tr>
<td>编号</td>
<td>姓名</td>
<td>年龄</td>
</tr>
</thead>
<tbody>
<tr>
<td>111</td>
<td>姓名</td>
<td>13</td>
</tr>
<tr>
<td>222</td>
<td>姓名</td>
<td>35</td>
</tr>
<tr>
<td>333</td>
<td>姓名</td>
<td>346</td>
</tr>
<tr>
<td>444</td>
<td>姓名</td>
<td>23</td>
</tr>
<tr>
<td>555</td>
<td>姓名</td>
<td>23</td>
</tr>
<tr>
<td>666</td>
<td>姓名</td>
<td>12</td>
</tr>
<tr>
<td>777</td>
<td>姓名</td>
<td>32</td>
</tr>
<tr>
<td>888</td>
<td>姓名</td>
<td>23</td>
</tr>
<tr>
<td>999</td>
<td>姓名</td>
<td>14</td>
</tr>
</tbody>
</table>
</body>
</html>
以上是关于表格隔行变色效果,鼠标悬浮高亮显示的主要内容,如果未能解决你的问题,请参考以下文章