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

发布于 2024-08-13 09:21:00 字数 124 浏览 2 评论 0原文

为什么这段代码:

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

...不起作用,我该如何修复它?

Why this code:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回梦 2024-08-20 09:21:00

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

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

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

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

The code works fine, as demonstrated with this Working Demo. Add /edit to the URL to see the code. Tested in Firefox 3.5 and 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>")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文