Jquery每个html

Jquery每个html,jquery,html,each,Jquery,Html,Each,我有密码: success: function( res ) { if( res.updated.length > 0 ) { $.each( res.updated, function( k,row ) { $( '.topStatsOuter' ).html( row.html ); }); } } 当我尝试alert(row.html)时,我得到了所有结果,但当我使用上述代码

我有密码:

success: function( res ) {                  
    if( res.updated.length > 0 ) {
        $.each( res.updated, function( k,row ) {
            $( '.topStatsOuter' ).html( row.html );
        });
    }
}
当我尝试alert(row.html)时,我得到了所有结果,但当我使用上述代码时。它只向div添加一个结果,为什么

编辑

已尝试追加。我原来的部门:

追加后: 我想覆盖,而不是添加相同的代码

您可以尝试以下操作:

success: function( res ) {                  
    if( res.updated.length > 0 ) {
        var html="";
        $.each( res.updated, function( k,row ) {
            html+=row.html;
        });
        $('.topStatsOuter').html(html);
    }
}

希望有帮助。

您目前正在做的是覆盖元素的内容(
$('.topStatsOuter').html(row.html);

您应该做的是首先清空元素的内容,然后使用循环追加结果。您的代码应如下所示:

success: function( res ) {                  
    if( res.updated.length > 0 ) {
        $( '.topStatsOuter' ).empty();
        $.each( res.updated, function( k,row ) {
            $( '.topStatsOuter' ).append( row.html );
        });
    }
}

尝试
$('.topStatsOuter').append(row.html)-因为您当前正在覆盖元素的内容(使用
html()
时)。您可以在循环之前添加
$('.topStatsOuter').empty()
,以删除以前的content@AlonEitan已尝试,而不是工作您是否尝试在
$之前清空元素
$('.topStatsOuter').emtpy()
。每个(res.updated,function(k,row){
行?什么是
res
?什么是
.topStatsOuter
?什么是
行.html
?请添加更多详细信息,以便我们可以复制您的代码。@AlonEitan非常感谢您!写一篇文章,我将其标记为答案