【发布时间】:2025-12-22 04:45:06
【问题描述】:
我有一个像这样的行和列的表
row1 1 2 3
row2 4
row3 5 6
并且这个序列被重复 n 次,这是一个单品的购物车表。 我需要在下一页上显示同一个表格作为购物车内容的摘要,在这样的表格中的一行中显示产品的所有字段:
row1 2 3 4 5 6
所以所有字段都需要在一行上,并且购物车中的第二个项目在第二行等等..,第一列(td)是一个 img 将被删除,第 4、5 和第 6 个是输入文本字段,需要转换为文本标签并与项目的其他字段在同一行。我知道我可以通过以下方式获取表格内容:$( "#id_of_table_clone" ).html( $( "#table_cart" ).html() );
如何自定义行结构以添加包含下面行内容的列?
添加包含 2 个项目的购物车内容的图像,我希望将“业务理由”、“开始日期”和“结束日期”作为列标题,并将它们的内容作为行内容值全部放在一行中,并带有角色和描述。
这是购物车表格的 html
<table id="table_rolecart"class="table sortable" cellspacing="0" width="100%">
<thead>
<tr>
<th class="sorting" style="width: 5%" scope="col">
off
</th>
<th scope="col" style="width: 40%">
<span class="column-sort" >
<a href="#" title="Sort up" class="sort-up"></a>
<a href="#" title="Sort down" class="sort-down"></a>
</span>
Role
</th>
<th scope="col" style="width: 55%">
<span class="column-sort" >
<a href="#" title="Sort up" class="sort-up"></a>
<a href="#" title="Sort down" class="sort-down"></a>
</span>
Description
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
然后我将 tbody 项插入到该表中,就像从另一个表外部插入一样
$("#table_newrole img.move-row").live("click", function() {
var tr = $(this).closest("tr").remove().clone();
tr.find("img.move-row")
.attr("src", "/gra/images/icons/fugue/cross-circle.png")
.attr("alt", "Remove");
$("#table_rolecart tbody").append(tr);
$("#table_rolecart tbody").append('<tr style="color:black"><td colspan="3">Business Justification: <input type="text" name="ar_businessjust" value="" id="ar_businessjust"></td></tr><tr style="color:black"><td colspan="2">Start Date: <input type="text" style="width:70px" name="ar_startdate" value="" id="ar_startdate"> </td><td colspan="1">End Date: <input type="text" style="width:70px" name="ar_enddate" value="" id="ar_enddate"></td></tr><tr style="height:8px"></tr>');
});
【问题讨论】:
-
如何渲染一项?请同时显示 html。