0

我需要从 JSON 数据源动态填充表格页脚。这是桌子的结构

<table  id="example_table">
<tfoot id="example_footer">
<tr id="example-footer" style="font-weight:bold">
<th></th>
<th></th>
<th></th>
<th></th>                                           
<th></th>
</tr>
</tfoot>  
</table>

我打算在 jQuery 中使用 append(),如下所示

$('#example_footer').append( '<tr>...</tr>' );

谁能告诉我如何访问 tfooter 并从 js 变量的内容中赋值

4

1 回答 1

1

这实际上取决于您的 JSON 的结构。假设它是在变量“数据”中接收到的并且它有 5 个元素,那么 javascript 会有点像:

var tr = '<tr>';
tr+= '<th>'+data.element1+'</th>';
tr+= '<th>'+data.element2+'</th>';
tr+= '<th>'+data.element3+'</th>';
tr+= '<th>'+data.element4+'</th>';
tr+= '<th>'+data.element5+'</th>';
tr+= '</tr>';
$('#example_footer').append(tr);
于 2012-10-25T15:03:56.417 回答