table表格鼠标移动变色html静态页码代码
前端html代码:
- <table id="jhTable">
- <tr>
- <td>Row 1, Cell 1</td>
- <td>Row 1, Cell 2</td>
- </tr>
- <tr>
- <td>Row 2, Cell 1</td>
- <td>Row 2, Cell 2</td>
- </tr>
- </table>
复制代码 css代码:
- #jhTable tr:hover {
- background-color: #f5f5f5;
- }
复制代码 JS代码:
- document.addEventListener('DOMContentLoaded', function() {
- var table = document.getElementById('myTable');
- table.addEventListener('mouseover', function(e) {
- if (e.target.tagName.toUpperCase() === 'TD') {
- e.target.parentNode.style.backgroundColor = '#f5f5f5';
- }
- });
- table.addEventListener('mouseout', function(e) {
- if (e.target.tagName.toUpperCase() === 'TD') {
- e.target.parentNode.style.backgroundColor = '';
- }
- });
- });
复制代码
|
|