• 案例 :表格隔行变色效果


    当鼠标落在表格某一行行,某一行变粉色 当离开恢复原色

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            table {
                 800px;
                margin: 100px;
                text-align: center;
                border-collapse: collapse;
                font-size: 14px;
            }
    
            thead tr {
                height: 20px;
                background-attachment: skyblue;
            }
    
            tbody tr {
                height: 30px;
            }
    
            tbody td {
                border-bottom: 1px;
                font-size: 12px;
                color: blue;
            }
    
            .bg {
                background-color: pink;
            }
        </style>
    </head>
    <body>
        <table>
            <thead>
                <tr>
                    <th>代码</th>
                    <th>名称</th>
                    <th>最新公布净值</th>
                    <th>累计净值</th>
                    <th>前单位净值</th>
                    <th>净增长率</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>112</td>
                    <td>农银金穗3个月定期开放债券</td>
                    <td>1.083</td>
                    <td>1.08</td>
                    <td>1.009</td>
                    <td>+0.33%</td>
                </tr>
    
                <tr>
                    <td>113</td>
                    <td>农银金穗3个月定期开放债券</td>
                    <td>1.083</td>
                    <td>1.08</td>
                    <td>1.009</td>
                    <td>+0.33%</td>
                </tr>
    
                <tr>
                    <td>114</td>
                    <td>农银金穗3个月定期开放债券</td>
                    <td>1.083</td>
                    <td>1.08</td>
                    <td>1.009</td>
                    <td>+0.33%</td>
                </tr>
    
                <tr>
                    <td>115</td>
                    <td>农银金穗3个月定期开放债券</td>
                    <td>1.083</td>
                    <td>1.08</td>
                    <td>1.009</td>
                    <td>+0.33%</td>
                </tr>
    
                <tr>
                    <td>116</td>
                    <td>农银金穗3个月定期开放债券</td>
                    <td>1.083</td>
                    <td>1.08</td>
                    <td>1.009</td>
                    <td>+0.33%</td>
                </tr>
            </tbody>
        </table>
        <script>
            //1.获取元素 获取的是tbody里面所有的行
            var trs = document.querySelector('tbody').querySelectorAll('tr');
            //2.利用循环 绑定注册事件
            for(var i = 0 ; i < trs.length ;i++)
            {
                //3.鼠标经过事件onmouseover
                trs[i].onmouseover = function() {
                    console.log('绑定成功');
                    this.className = 'bg';
                }
                trs[i].onmouseout = function() {
                    this.className = '';
                }
            }
        </script>
    </body>
    </html>
  • 相关阅读:
    React Virtual Dom 与 Diff
    打造前端CI/CD工作流
    webpack-chain明细
    React项目中实现多语言支持
    【WPF】大量Canvas转换为本地图片遇到的问题
    【C#】【分享】 XX分钟学会C#
    【WPF】一些拖拽实现方法的总结(Window,UserControl)
    【WPF】 InkCanvas 书写毛笔效果
    js中this指向问题
    js原型浅谈理解
  • 原文地址:https://www.cnblogs.com/qiujie-prion/p/13026013.html
Copyright © 2020-2023  润新知