【发布时间】:2011-12-26 10:45:12
【问题描述】:
$('#all_locations').append("<table>");
$('#all_locations').append("<tr><th>City</th></tr>");
$.each(data, function(i, item){
$('#all_locations').append("<tr>");
$('#all_locations').append("<td>"+item.city+"</td>");
$('#all_locations').append("<tr>");
}
$('#all_locations').append("</table>");
使用alert($('#all_locations').html());得到的输出
<table></table>
<tr><th>City</th></tr>
<tr></tr><td>Seattle</td>
<tr></tr><td>Chicago</td>
此代码在 ajax 调用完成时触发。任何想法为什么会这样做?
假设数据变量是有效的 JSON 对象。
【问题讨论】:
标签: jquery html json html-table append