用jQuery填充HTML表 [英] populate html table with jquery
本文介绍了用jQuery填充HTML表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有表,并且我想通过jquery在表中间添加数据.
suppose i have table and i want to append data in the middle of table through jquery.
<table border="1">
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
在这里,我需要在jQuery后面附加tr
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
jquery有可能吗?如果是这样,那么请指导我. 如果我可以填充,那么我可以像
is it possible with jquery? if so then please guide me. if i can populate then i can do like
for (var i = 0; i < data.d.length; i++) {
$("#NamesGridView").append("<tr><td>" + data.d[i].FirstName +
"</td><td>" + data.d[i].Age + "</td></tr>");
}
}
请指导谢谢
推荐答案
编辑基于评论:
$('#thetable tr').not(':first').not(':last').remove();
var html = '';
for(var i = 0; i < data.d.length; i++)
html += '<tr><td>' + data.d[i].FirstName +
'</td><td>' + data.d[i].Age + '</td></tr>';
$('#thetable tr').first().after(html);
此处的示例: JSFiddle
这篇关于用jQuery填充HTML表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文