Web API 排他操作案例 —— 表格隔行变色

本文通过实例讲解如何利用JavaScript的onmouseover和onmouseout事件实现Web API中表格的隔行变色效果。在鼠标经过tbody内的tr行时,该行背景色会改变,鼠标离开时恢复原状。注意thead中的行不参与变色处理。
摘要由CSDN通过智能技术生成

学习来源: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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值