javascript 将表格单元格添加到现有表格行,jQuery
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7875176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add table cell to existing table row, jQuery
提问by SystemError
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. For example:
我正在尝试使用 jQuery 向表中添加值 - 不幸的是,我不知道如何让 jQuery 将表单元格添加到现有行。例如:
$("<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
. What would be the best way to go about adding cells to an existing table row (<tr>
) using jQuery? Quick google hasn't revealed anything.
Regards,
这将使用 id 将单元格添加到表格的末尾table1
。<tr>
使用 jQuery将单元格添加到现有表格行 ( )的最佳方法是什么?快速谷歌没有透露任何东西。问候,
SystemError
系统错误
回答by Mike Thomsen
.appendTo('#table1 #rowId');
Or you could do:
或者你可以这样做:
.appendTo('#table1 tr:nth-child(5)');
回答by Nicola Peluchetti
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');