与以前使用的方法相比,我在工作中学会了一种更全面的方法(请参阅此处)。我发现自己使用下面的代码。我想将最后一个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'}))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句