更改表格行tr的背景颜色

一.业务代码说明:
制作一张商品信息表格,要求当鼠标移动到表格某一行的时候此行的背景颜色集会发生变化,当鼠标移开其背景颜色就会恢复为白色。

具体代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>change table row backGroundColor</title>
    <style>
        tr{
   text-align: center}
        caption{
   margin: 25px}
        .tr1{
   background-color: bisque}
        .tr2{
   background-color: white}

    </style>
    <script>
        let changeTrBGColor = function () {
   
            let trs = document.getElementsByTagName("tr");
            for(let i=1;i<trs.length;i++){
   
                trs[i].onmouseover = function(){
   
                    trs[i].className = "tr1";
                }
                trs[i].onmouseout = function(){
   
                    trs[i].className = "tr2";
                }
            }
        }
        window.onload = function () {
   
            changeTrBGColor();
        }
    </script>
</head>
<body>
    <table id="table1" border="2px" align="center" cellspacing="0px"
           width="40%" cellpadding="10px">
        <caption>商品信息表</caption>
        <tr>
            <th>商品编号</th>
            <th>商品名称</th>
            <th>商品价格</th>
        </tr>
        <tr>
            <td>1001</td>
            <td>洗衣机</td>
            <td>2800</td>
        
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值