在表中动态插入新行
<script type="text/javascript" language="javascript">
function addNewRow()
{
var table = document.getElementById("table1");
var tr = table.insertRow();
var td = tr.insertCell();
td.innerHTML= "a";
td = tr.insertCell();
td.innerHTML= "b";
td = tr.insertCell();
td.innerHTML= "c";
td = tr.insertCell();
td.innerHTML= "d";
td = tr.insertCell();
td.innerHTML= "e";
}
</script>
<body>
<table id="table1" border="1" cellpadding="0" cellspacing="0" width="100%">
<tr id="row1">
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
<input type="button" onClick="addNewRow()" value="Add New"/>
</body>
此示例用于在表中动态插入新行和单元格。 但它的行为在所有浏览器中都不同。
Internet Explorer = 在最后添加行,新添加的单元格从第一个开始。
Chrome/Safari = 它在第一个中添加新行,并且新添加的单元格从末尾开始。
Mozilla Firefox = 无法正常工作。
我希望在最后一个新添加的行,并且新添加的单元格从第一个开始,就像所有浏览器中的 (Internet Explorer) 一样。
如果您对相同行为有任何解决方案,请告诉我。
<script type="text/javascript" language="javascript">
function addNewRow()
{
var table = document.getElementById("table1");
var tr = table.insertRow();
var td = tr.insertCell();
td.innerHTML= "a";
td = tr.insertCell();
td.innerHTML= "b";
td = tr.insertCell();
td.innerHTML= "c";
td = tr.insertCell();
td.innerHTML= "d";
td = tr.insertCell();
td.innerHTML= "e";
}
</script>
<body>
<table id="table1" border="1" cellpadding="0" cellspacing="0" width="100%">
<tr id="row1">
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
<input type="button" onClick="addNewRow()" value="Add New"/>
</body>
This example is for dynamically insert new row and cells in the table.
But its behavior is different in all browsers.
Internet Explorer = It add row in the last and new added cells are starts from first.
Chrome/Safari = It add new row in the first and new added cells are starts from end.
Mozilla Firefox = It is not working.
I want new added row in the last and new added cells starts from first like (Internet Explorer) in all browsers.
If you have any solution for same behavior please tell me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用:
就像这里所说的:
https://developer.mozilla.org/en /DOM/table.insertRow
try to use:
like its said here:
https://developer.mozilla.org/en/DOM/table.insertRow