使用 jQuery 向表格数据单元格添加文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1855137/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:16:24  来源:igfitidea点击:

Adding text to a table data cell with jQuery

jqueryhtml-tabledom-manipulation

提问by user169242

Why this code:

为什么这个代码:

row.append($("<td></td>").text("someText"));

...isn't working, and how can I fix it?

...不起作用,我该如何解决?

回答by Russ Cam

The code works fine, as demonstrated with this Working Demo. Add /editto the URL to see the code. Tested in Firefox 3.5 and IE 6

代码工作正常,如本工作演示所示。将/edit添加到 URL 以查看代码。在 Firefox 3.5 和 IE 6 中测试

$('button').one('click', function() {
  $('#myTable tr:last').append($("<td></td>").text("someText"));
});

Also, you might consider shortening the creation of the cell element to

此外,您可能会考虑将单元格元素的创建时间缩短为

$("<td>someText</td>")