首页 > 代码库 > 表格隔行变色效果,鼠标悬浮高亮显示
表格隔行变色效果,鼠标悬浮高亮显示
<!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>
表格隔行变色效果,鼠标悬浮高亮显示
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。