javascript - 如何使用 Jquery 在 HTML 表格中添加行?

标签 javascript jquery html asp.net

我想在运行时使用 Jquery 动态添加行。开始表没有任何记录。当用户单击 ADD 按钮 时,它必须添加行。 Watch this picture

当用户单击ADD 按钮 时,运算符下拉列表框值和过滤器值应添加到该表行中。

这是我试过的 Jquery代码

$("#btnAdd").click(function () {

   // $("#queryTable tr:last").after("<tr>...</tr><tr>...</tr>");
    $('#queryTable > tbody:last-child').append('<tr>Record1</tr><tr>Record2</tr>');
});

两条线路我都试过了。但这没有任何意义。 谢谢

HTML 代码

 <table class="table table-hover " id="queryTable">
     <thead>
         <tr>
             <th>Field Name</th>
             <th>Values</th>
         </tr>
     </thead>
     <tbody>
         <tr>
             <td>Mark</td>  //Please ignore these two records. At beginning the table will be empty
             <td>Otto</td>
         </tr>
         <tr>
             <td>Jacob</td>
             <td>Thornton</td>
         </tr>
     </tbody>
 </table>

最佳答案

添加 HTML 元素的正确 jQuery 代码是:

$('#queryTable tbody').append('<tr><td>Record1</td><td>Record2</td></tr>');

关于javascript - 如何使用 Jquery 在 HTML 表格中添加行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41995372/

相关文章:

javascript - 如何在 React Native 中打开 HTTP 服务器

javascript - 从 Vanillamodal iframe 中隐藏/删除滚动条

javascript - 我可以使用/^USA$/进行精确匹配吗?安全吗?有更好的主意吗?

javascript - 让自定义 jQuery 选项卡系统正常工作

javascript - 在同一页面上多次显示wavesurfer.js

html - react 最佳实践 : logic vs functions in JSX

javascript - 在表中添加更多行时使用js重新排序表

javascript - 将 jQuery 函数应用于表行但不应用于第一个表数据

javascript - Onclick 事件未触发(这太基本了,我要疯了吗?)

javascript - file_put_content 数组结构不起作用