我有代碼:jQuery的每個HTML
success: function(res) {
if(res.updated.length > 0) {
$.each(res.updated, function(k,row) {
$('.topStatsOuter').html(row.html);
});
}
}
當我嘗試警報(row.html),我得到的所有結果,但是當我使用的代碼如上。它只爲div添加一個結果,爲什麼?
編輯。
嘗試追加。我原來的div: http://image.prntscr.com/image/3ac6dc5a137e46ababff6acd6bfc2a1a.png
追加後: http://image.prntscr.com/image/6b9a2fc093c0440a8d39afd8db0dc274.png 我想覆蓋,不添加相同的代碼
嘗試'$( '.topStatsOuter').append(row.html);' - 因爲你目前覆蓋元素的含量(當使用'HTML()') 。您可以在循環前添加'$('.topStatsOuter').empty()'以刪除任何以前的內容 –
@AlonEitan嘗試過,不行的 – EvaldasL
您是否嘗試清空元素'$('.topStatsOuter').emtpy )''.each之前''.each(res.updated,function(k,row){'line? –