<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
thead {
background-color: #555555;
color: green
}
tbody {
background-color: #7cd1f9;
color: blue;
height: 50px
}
tfoot {
background-color: #888888;
color: red
}
.bg{
background-color: pink;
}
</style>
</head>
<body>
<table border="1">
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
</table>
<script>
var trs=document.querySelector('tbody').querySelectorAll('tr');
for (var i=0;i<trs.length;i++){
trs[i].onmouseover=function () {
console.log(1);
this.className='bg';
}
trs[i].onmouseleave=function () {
this.className='tbody';
}
}
</script>
</body>
</html>
js实现鼠标悬浮时表格对应行变色
最新推荐文章于 2024-01-06 15:06:54 发布