利用js在Table中追加数据

<div >
    <table id="divData" class="table-bordered table"  style="margin-top:20px">
        <tr id="wahha">
        <td>编号</td>
        <td>类型</td>
            <td>操作</td>
        </tr>

    </table>
</div>
<script>

    window.onload = function LoadFun() {
        $.ajax({
            url: 'https://localhost:44374/api/carinfo/gettype',
            type: 'get',
            success: function (d) {
                console.log(d);
                var a = "";
      
                $(d).each(function () {
                    a += '<tr><td>' + this.Id + '</td> <td>' + this.CarTypeName + '</td><td><input id="button1" type="button" value="删除" class="btn-link btn" style="color:red" onclick="fun1('+this.Id + ')"/><input id="button1" type="button" value="修改" class="btn-link btn" style="color:blue" onclick="fun2('+this.Id + ')"/></td> </tr>';
                })
                console.log(a);
                $("#divData").append(a)
            }
        })
    }
</script>

posted @ 2020-01-07 15:41  看花人墨客  阅读(1593)  评论(0编辑  收藏  举报