怎么把每个内部追加?

时间:2018-04-20 03:09:29

标签: javascript jquery append each

这是我的代码

$('#payment_detail').append(
                        '<table class="table table-bordered table-striped">'+
                        '<thead>'+
                        '<th>Payment Date</th>'+
                        '<th>Payment Value</th>'+
                        '<th>Verified By</th>'+
                        '</thead>'+
                        '<tbody>'+
                            $.each(response.payments, function (key, value) {
                                return '<td>'+ value.payment_date +'</td> <td>'+ value.payment_value +'</td> <td>'+ value.created_by +'</td>'
                            })+
                        '</tbody>'+
                        '</table>'
                    );

但视图看起来像这样 enter image description here

有人能帮帮我吗?感谢

1 个答案:

答案 0 :(得分:0)

试试这个

('#payment_detail').append(
                        '<table class="table table-bordered table-striped">'+
                        '<thead>'+
                        '<th>Payment Date</th>'+
                        '<th>Payment Value</th>'+
                        '<th>Verified By</th>'+
                        '</thead>'+
                        '<tbody id="dtDetails"></tbody></table>');

    $.each(response.payments, function (key, value) {
        $("#dtDetails").append('<tr><td>' + value.payment_date + '</td> <td>' + value.payment_value + '</td> <td>' + value.created_by + '</td></tr>');
    });