![](/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.