学习来源:https://www.bilibili.com/video/BV1HJ41147DG
思路
- 用到新的鼠标事件鼠标经过 onmouseover、鼠标离开 onmouseout
- 鼠标经过 tr 行,当前的行变背景颜色,鼠标离开去掉当前的背景颜色
- 注意:第一行( thead 里面的行)不需要变换颜色,因此我们获取的是 tbody 里面的行
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
table {
font-size: 14px;
text-align: center;
border-collapse: collapse;
}
th,
td {
padding: 5px 7px;
border-bottom: 1px solid #dfdfe5;
}
th {
color: #4148bf;
font-weight: 600