让我说请求(ajax)一些记录,返回:
[
[ID: 1, name: 'fdssdfdsf'],
[ID: 2, name: 'vxcvxcvxcv'],
[ID: 3, name: '333333']
]
,应该显示:
try
{
answer = $.parseJSON(answer);
targetDiv.html('');
for(var record in answer)
{
record = answer[record];
/////////////
}
}
catch(e)
{
alert('Server is down!');
}
现在我可以看到两种方式:
通过创建DOM-s来完成:
var cloneFrom = $('<div>');
cloneFrom.addClass('container');
cloneFrom.append($('<div>').addClass('date').text(record.post_title));
targetDiv.append(cloneFrom);
或创建&#34; raw&#34;
var s = '';
s+= '<div>'+record.post_title+'</div>';
哪一个可能是最好的?第二个似乎更容易