js动态添加行列后如何取得添中在input里的name值!在线等,急呀!
一潭清水 2009-08-06 08:16:15 请高手指教!我想实现获得新增部分AA和BB的值!然后代入公式进行计算!
这是代码//
<table width="400" border="0" cellspacing="0" cellpadding="0" id="tblGrid">
<tr>
<td align="center">AA</td><td>
<input type="text" name="tj_hight" id="hight" size="5" ></td><td>
CM × BB</td><td>
<input type="text" name="tj_width" id="width" size="5" ></td><td>
CM </td><td><a href="javascript:void(0)" onclick="addRow1()">[新增]</a> </td>
</tr>
</table>
<script language="javascript">
//add a new row to the table
function addRow1()
{
//add a row to the rows collection and get a reference to the newly added row
var newRow = document.all("tblGrid").insertRow();
//add 3 cells (<td>) to the new row and set the innerHTML to contain text boxes
var oCell = newRow.insertCell();
oCell.innerHTML = " AA";
oCell = newRow.insertCell();
oCell.innerHTML = "<input type='text' name='hight' size=5>";
oCell = newRow.insertCell();
oCell.innerHTML = " CM × BB";
oCell = newRow.insertCell();
oCell.innerHTML = "<input type='text' name='width' size=5> ";
oCell = newRow.insertCell();
oCell.innerHTML = "CM ";
oCell = newRow.insertCell();
oCell.innerHTML = "<input type='button' value='Delete' onclick='removeRow1(this);'>";
}
//deletes the specified row from the table
function removeRow1(src)
{
/* src refers to the input button that was clicked.
to get a reference to the containing <tr> element,
get the parent of the parent (in this case case <tr>)
*/
var oRow = src.parentElement.parentElement;
//once the row reference is obtained, delete it passing in its rowIndex
document.all("tblGrid").deleteRow(oRow.rowIndex);
}
</script>