我一直在嘗試索引我的錶行但未成功。我能做的最好的是提出代碼,可以重新索引表中的每一行,每當我添加新的表格行時,但它不起作用。我認爲語法有些問題,但我不確定是什麼。 JS部分:索引錶行js/jquery
$("#pridet").click(function(){
$("table tbody tr").first().clone().prependTo("table tbody");
var x = document.getElementsByTagName("tr");
document.getElementsByName("tabelis").innerHTML = x.rowIndex;
});
我知道什麼是致命錯誤的第二部分上的HTML文件
代碼(如指揮到哪裏,也許寫什麼指標?):
<button id = "pridet">pridet</button>
<table id="myTable" class="table table-inverse">
<thead id = "headings" class = "thead-default">
<tr>
<th>Tabelio Nr.</th>
<th>Vardas</th>
<th>Pavardė</th>
<th>Pareigos</th>
<th>Bazinė alga, €</th>
<th>Valandinis atlyginimas, €</th>
<th>Veiksmai</th>
</tr>
</thead>
<tfoot class = "thead-default">
<tr>
<td>Vidurkis</td>
<td></td>
<td></td>
<td></td>
<td>10000</td>
<td>17.3</td>
<td></td>
</tr>
</tfoot>
<tbody>
<tr>
<td class = "tabelis">1</td>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
<td>bla</td>
<td><input type="button" value="Delete" onclick="deleteRow(this)"></td>
<td>
<p class = "btn" style = "width:10%; padding-bottom:0; margin-bottom:0; border-bottom:0"><span class = "fa fa-edit"></span></p>
<p class = "btn" style = "width:10%; padding-bottom:0; margin-bottom:0; border-bottom:0" onclick="deleteRow(this)"><span class = "fa fa-trash"></span></p>
</td>
</tr>
<tr>
<td class = "tabelis">2</td>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
<td>bla</td>
<td>blum</td>
<td>
<!-- <p class = "btn" style = "width:10%; padding-bottom:0; margin-bottom:0; border-bottom:0"><span class = "fa fa-edit"></span></p> -->
<!-- <p class = "btn" style = "width:10%; padding-bottom:0; margin-bottom:0; border-bottom:0"><span class = "fa fa-trash"></span></p> -->
</td>
</tr>
<tr>
<td class = "tabelis">3</td>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
<td>bla</td>
<td>blum</td>
<td>
<!-- <p class = "btn" style = "width:10%; padding-bottom:0; margin-bottom:0; border-bottom:0"><span class = "fa fa-edit"></span></p> -->
<!-- <p class = "btn" style = "width:10%; padding-bottom:0; margin-bottom:0; border-bottom:0"><span class = "fa fa-trash"></span></p> -->
</td>
</tr>
</tbody>
</table>
<script src="script.js" charset="utf-8"></script>
<script>
function deleteRow(r) {
var i = r.parentNode.parentNode.rowIndex;
document.getElementById("myTable").deleteRow(i);
};
</script>
我大概可以計算行的總數像這樣的東西
$("#counter").text($("table tbody tr").length);
,並使用該值inser T編號爲表格單元格莫名其妙
編輯:didnt之前提到這一點,但表中的行必須EB添加在表的頂部(以下THEAD)
嘗試在表的底部添加行。計算表中的行數,並將計數加1,並將其推入最後一行的第一個td中。 – Sinha