JavaScript implements color identification when the mouse passes over the table row

JavaScript implements color identification when the mouse passes over the table row

This article shares with you how to use JavaScript to give color labels when the mouse passes over a table row. The specific content is as follows

Code:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        table {
            margin: 100px auto;
            width: 800px;
            border-spacing: 0;
            text-align: center;
        }
        
        table tr:nth-child(1) {
            background-color: rgb(135, 206, 235);
        }
        
        table tr:nth-child(n+2) {
            border-bottom: 1px solid black;
        }
        
        th {
            font-size: 14px;
            padding-top: 5px;
            padding-bottom: 5px;
        }
        
        td {
            font-size: 12px;
            padding-top: 8px;
            padding-bottom: 8px;
            color: blue;
            border-bottom: 1px solid lightgray;
        }
    </style>
</head>

<body>
    <table>
        <tr>
            <th>Code</th>
            <th>Name</th>
            <th>Latest published net worth</th>
            <th>Accumulated net value</th>
            <th>Previous unit net value</th>
            <th>Net asset growth rate</th>
        </tr>
        <tr>
            <td>003526</td>
            <td>Agricultural Bank of China Jinsui 3-month regular open bond</td>
            <td>1.075</td>
            <td>1.079</td>
            <td>1.074</td>
            +0.047%
        </tr>
        <tr>
            <td>003526</td>
            <td>Agricultural Bank of China Jinsui 3-month regular open bond</td>
            <td>1.075</td>
            <td>1.079</td>
            <td>1.074</td>
            +0.047%
        </tr>
        <tr>
            <td>003526</td>
            <td>Agricultural Bank of China Jinsui 3-month regular open bond</td>
            <td>1.075</td>
            <td>1.079</td>
            <td>1.074</td>
            +0.047%
        </tr>
        <tr>
            <td>003526</td>
            <td>Agricultural Bank of China Jinsui 3-month regular open bond</td>
            <td>1.075</td>
            <td>1.079</td>
            <td>1.074</td>
            +0.047%
        </tr>
        <tr>
            <td>003526</td>
            <td>Agricultural Bank of China Jinsui 3-month regular open bond</td>
            <td>1.075</td>
            <td>1.079</td>
            <td>1.074</td>
            +0.047%
        </tr>
        <tr>
            <td>003526</td>
            <td>Agricultural Bank of China Jinsui 3-month regular open bond</td>
            <td>1.075</td>
            <td>1.079</td>
            <td>1.074</td>
            +0.047%
        </tr>


    </table>

    <script>
        var rows = document.querySelectorAll(' table tr:nth-child(n+2)');
        for (var i = 0; i < rows.length; i++) {
            rows[i].onmouseover = function() {
                this.style.backgroundColor = "lightblue";
            }
            rows[i].onmouseout = function() {
                this.style.backgroundColor = "";
            }
        }
    </script>
</body>

</html>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • js method to change the color of table rows when the mouse passes over them
  • Playing sound when the mouse passes over in Javascript

<<:  Solve the problem of MYSQL connection port being occupied and introducing file path errors

>>:  How to build a standardized vmware image for kubernetes under rancher

Recommend

Several ways to easily traverse object properties in JS

Table of contents 1. Self-enumerable properties 2...

Example of how to quickly delete a 2T table in mysql in Innodb

Preface This article mainly introduces the releva...

Solution to Apache cross-domain resource access error

In many cases, large and medium-sized websites wi...

Detailed explanation of the process of modifying Nginx files in centos7 docker

1. Install nginx in docker: It is very simple to ...

How to install Apache service in Linux operating system

Download link: Operating Environment CentOS 7.6 i...

Media query combined with rem layout in CSS3 to adapt to mobile screens

CSS3 syntax: (1rem = 100px for a 750px design) @m...

A brief discussion on several situations where MySQL returns Boolean types

mysql returns Boolean type In the first case, ret...

Detailed tutorial on installing MySQL 8.0.20 database on CentOS 7

Related reading: MySQL8.0.20 installation tutoria...

10 skills that make front-end developers worth millions

The skills that front-end developers need to mast...

Solution to nacos not being able to connect to mysql

reason The mysql version that nacos's pom dep...

Analysis of the principle and usage of MySQL continuous aggregation

This article uses examples to illustrate the prin...

About installing python3.8 image in docker

Docker Hub official website 1. Search for Python ...

This article teaches you how to play with CSS combination selectors

CSS combination selectors include various combina...

How to modify Flash SWF files in web pages

I think this is a problem that many people have en...