![](/img/trans.png)
[英]Dynamically adding a row at the bottom of a table using onblur event in Javascript (with out button)
[英]Dynamically adding a row in the table onblur the last row in the table using javascript
我創建了一個表,在引用“http://stackoverflow.com/questions/9045940/dynamically-adding-table-row”時,每當我進入表格的最后一行時,我需要在表格中添加另一行動態下,這是我試過的代碼:
<table id="myTable" style="table-layout:auto">
<tr>
<td><input type="text" onblur="addRow('myTable')" /></td>
<td><input type="text"/></td>
<td><input type="text"/></td>
</tr>
</table>
和javascript如下:
<script>
function addRow()
{
//add a row to the rows collection and get a reference to the newly added row
var newRow = document.all("myTable").insertRow();
var oCell = newRow.insertCell();
oCell.innerHTML = "<input type='text' onblur='addRow();'>";
oCell = newRow.insertCell();
oCell.innerHTML = "<input type='text' name='title'>";
oCell = newRow.insertCell();
oCell.innerHTML = "<input type='text' name='title'>";
}
</script>
但是,這里在表格的頂部添加了一個新行,我該怎么辦?
change var newRow = document.all("myTable").insertRow();
至
var newRow = document.all("myTable").insertRow(-1);
另外,在你的onblur
事件中,為什么在不帶任何參數的情況下將參數傳遞給addRow
函數呢?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.