gpt4 book ai didi

javascript - 使用 jQuery 将 td 附加到表中的 tr

转载 作者:行者123 更新时间:2023-11-30 17:05:32 24 4
gpt4 key购买 nike

我在工作中学到了一种比我以前使用的方法更全面的方法 (see here)。我发现自己使用下面的代码。我想将最后一个 td (col2) 添加到父 tr 而不是之前的 td (col1)。如何进行?

我到处找,但我没有找到我的问题的答案......

$('.main').append(
$('<div>', {'class' : 'box'}).append(
$('<div>', {'class' : 'table_responsive'}).append(
$('<table>', {'class' : 'table'}).append(
$('<tbody>').append(
$('<tr>').append(
$('<td>', {'class' : 'text-center', 'text' : 'col1'}).append(
$('<td>', {'class' : 'text-center', 'text' : 'col2'})
)
)
)
)
)
)
);

最佳答案

您只需要移动 .append() 以跟随 tr 声明,而不是 td:

$('<tr>')
.append($('<td>', {'class' : 'text-center', 'text' : 'col1'}))
.append($('<td>', {'class' : 'text-center', 'text' : 'col2'}))

关于javascript - 使用 jQuery 将 td 附加到表中的 tr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28106394/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com