<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <style> .haha { width: 100px; background: pink; position: absolute; top: 50px; left: 3px; } .td-style { position:relative; } </style> <body> <div> <table id="tableId"> <tr> <td> <span>888</span> </td> <td> <span>777</span> </td> </tr> </table> </div> <script> window.onload = function () { getWord(); } function getWord() { tableId = document.getElementById('tableId'); tdBrand = document.getElementsByTagName('td'); var span = document.createElement('div'); for (var i = 0; i < tdBrand.length; i++) { tdBrand[i].parentNode.className = 'td-style'; tdBrand[i].onmouseenter = function () { span.className = 'haha'; this.appendChild(span); span.innerText = this.textContent; } tdBrand[i].onmouseleave = function () { span.innerText = ''; } } } </script> </body> </html>
用原生js写浮窗显示 内容
最新推荐文章于 2022-06-05 15:17:59 发布