英 [in?s?:t r?u]? ?美 [?n?s?t ro]??

[計] 插入行

javascript insertRow()方法 語法

作用:用于在表格中的指定位置插入一個新行。

語法:tableObject.insertRow(index)

返回:返回一個 TableRow,表示新插入的行。

說明:該方法創(chuàng)建一個新的 TableRow 對象,表示一個新的 <tr> 標(biāo)記,并把它插入表中的指定位置。新行將被插入 index 所在行之前。若 index 等于表中的行數(shù),則新行將被附加到表的末尾。如果表是空的,則新行將被插入到一個新的 <tbody> 段,該段自身會被插入表中。

注釋:可以用 TableRow.insertCell() 方法給新創(chuàng)建的行添加內(nèi)容。

javascript insertRow()方法 示例

<html>
<head>
<script type="text/javascript">
function insRow()
  {
  document.getElementById('myTable').insertRow(0)
  }
</script>
</head>

<body>
<table id="myTable" border="1">
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
</table>
<br />
<input type="button" onclick="insRow()"
value="Insert new row">

</body>
</html>

運行實例 ?

點擊 "運行實例" 按鈕查看在線實例