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>
...全文
426 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
一潭清水 2009-08-06
问题已自行解决,谢谢2楼热心肠人!
回复
一潭清水 2009-08-06
<table width="400" border="0" cellspacing="0" cellpadding="0" id="tblGrid">
<tr>
<td align="center">长</td><td>
<input type="text" name="hight" id="hight" size="5" ></td>
<td> CM  × 宽</td><td>
<input type="text" name="tj_width" id="tj_width" size="5" ></td>
<td> CM  </td>
<td><a href="javascript:void(0)" onclick="addRow1()">[新增]</a> </td>
</tr> </table>

<script language="javascript">
function addRow1()
{
var newRow = document.all("tblGrid").insertRow();
var oCell = newRow.insertCell();
oCell.innerHTML = " 长";
oCell = newRow.insertCell();
oCell.innerHTML = "<input type='text' name='tj_hight' size=5>";
oCell = newRow.insertCell();
oCell.innerHTML = " CM  × 宽";
oCell = newRow.insertCell();
oCell.innerHTML = "<input type='text' name='tj_width' size=5> ";
oCell = newRow.insertCell();
oCell.innerHTML = "CM     ";
oCell = newRow.insertCell();
oCell.innerHTML = "<input type='button' value='Delete' onclick='removeRow1(this);'>";
}
function removeRow1(src)
{
var oRow = src.parentElement.parentElement;
document.all("tblGrid").deleteRow(oRow.rowIndex);
}
</script>
回复
norman3036383 2009-08-06
代码给出的具体点·一下这么多谁看啊
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告