Александр Asked:2020-02-17 19:57:05 +0000 UTC2020-02-17 19:57:05 +0000 UTC 2020-02-17 19:57:05 +0000 UTC 如何使元素出现在使用 JavaScript 或 jQuery 用 PHP 生成的表中? 772 我有一个包含三列的表(“数字”、“名称”和一个空列)。它是使用 PHP 生成的(将数据从数据库输出到模板)。 将鼠标悬停在表格中的一行上时,如何使按钮出现在该行的空列中? javascript 1 个回答 Voted Best Answer BlackStar1991 2020-02-17T20:26:30Z2020-02-17T20:26:30Z 嗯,像这样 $(".myTable tr:not(:nth-child(1))").hover( function() { $(this).find('td:last-child').append('<button class="myButton">My Button</button>'); }, function() { $('.myButton').remove(); } ); $("body").on("click", $('.myButton'), function() { alert("button click"); }) .myTable { width: 100%; min-height: 30px; border-collapse: collapse; } .myTable td { padding: 10px; border: 1px solid #000; text-align: center; } .myButton { border: 1px solid #000; color: #000; background-color: pink; padding: 10px; cursor: ponter; } <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table class="myTable"> <tr> <td>номер</td> <td>название</td> <td>пустой столбец</td> </tr> <tr> <td>1</td> <td>Text1</td> <td></td> </tr> <tr> <td>2</td> <td>Text2</td> <td></td> </tr> </table>
嗯,像这样