js添加表格的tr和td

表格样式(采用bootstrap)

<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered dataTable" id="example" aria-describedby="example_info">
                <thead>
                    <tr role="row">
                        <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending" style="width: 48px;">
                            标准
                        th>
                        <th class="sorting" role="columnheader" tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="width:10px;">
                            分数
                        th>
                    tr>
                thead>
                <tbody role="alert" aria-live="polite" aria-relevant="all" id="NewElemet">
                    <tr>
                        <td>123td>
                        <td>123td>
                    tr>
                    <tr>
                        <td>123td>
                        <td>123td>
                    tr>
                tbody>
            table>
标准 分数
123 123
123 123

js代码

     var Con = document.getElementById("NewElemet");
     var tr = document.createElement("tr");
     Con.appendChild(tr);
     var td = document.createElement("td");
     tr.appendChild(td);
     td.innerHTML = "aaaaa";
     var td2 = document.createElement("td");
     tr.appendChild(td2);
     td2.innerHTML = "bbbbb";

没运行一次添加一行,3次添加后

标准 分数
123 123
123 123
aaaaa bbbbb
aaaaa bbbbb
aaaaa bbbbb

你可能感兴趣的:(html,javascript,bootstrap)