jQuery 如何在 html 表格单元格中的 <TD> 末尾插入文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7778031/
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
How can I insert text at the end of a <TD> in a html table cell
提问by leora
I have a table and in a cell I have something like this . .
我有一张桌子,在一个单元格中,我有这样的东西。.
<td class="quantity">
[a bunch of spans and divs and all stuff]
</td>
I want to figure out in jquery how I could insert text at the bottom of the cell, so the result would be:
我想在 jquery 中弄清楚如何在单元格底部插入文本,所以结果是:
<td class="quantity">
[a bunch of spans and divs and all stuff]
inserted text
</td>
I need it to work, regardless of what else is in the td (in the "a bunch of spans and divs and all stuff" section.
我需要它工作,不管 td 中还有什么(在“一堆跨度和 div 以及所有东西”部分。
Is that possible?
那可能吗?
回答by fmsf
with jquery:
使用 jquery:
$("td.quantity").append("stuff you want to append");
The append function always adds to the end of the element you provided. In this case it will add to all the td
with the class quantity
append 函数总是添加到您提供的元素的末尾。在这种情况下,它将添加到所有td
的类quantity