简体   繁体   English

将表格单元格添加到现有表格行jQuery

[英]Add table cell to existing table row, jQuery

I'm trying to add values to a table using jQuery - unfortunately, I don't know how to get jQuery to add table cells to an existing row. 我正在尝试使用jQuery向表中添加值 - 遗憾的是,我不知道如何让jQuery将表单元格添加到现有行。 For example: 例如:

$("<td><a href='#'>" + key + "</a></td>").click(function(e) {
    e.preventDefault();
    testset(key);
}).appendTo('#table1');

This adds cells to the end of the table with id table1 . 这将使用id table1将单元格添加到表的末尾。 What would be the best way to go about adding cells to an existing table row ( <tr> ) using jQuery? 使用jQuery将单元格添加到现有表行( <tr> )的最佳方法是什么? Quick google hasn't revealed anything. 快速谷歌没有透露任何东西。 Regards, 问候,

SystemError 系统错误

.appendTo('#table1 #rowId');

Or you could do: 或者你可以这样做:

.appendTo('#table1 tr:nth-child(5)');

http://api.jquery.com/nth-child-selector/ http://api.jquery.com/nth-child-selector/

You must append them to a specific row and not to the table: 您必须将它们附加到特定行而不是表格:

$("<td><a href='#'>" + key + "</a></td>").click(function(e) {
    e.preventDefault();
    testset(key);
}).appendTo('#table1 tr#yourrowId');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM