- 爱易网页
-
ASP.NET教程
- 怎么获取table中动态添加行的控件和它的值
日期:2014-05-18 浏览次数:20434 次
如何获取table中动态添加行的控件和它的值
我的代码如下:
客户端代码:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
var p, i, foundObj;
if(!theDoc) theDoc = document;
if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
{
theDoc = parent.frames[theObj.substring(p+1)].document;
theObj = theObj.substring(0,p);
}
if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
for (i=0; !foundObj && i < theDoc.forms.length; i++)
foundObj = theDoc.forms[i][theObj];
for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
foundObj = findObj(theObj,theDoc.layers[i].document);
if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
return foundObj;
}
//添加一个参与人填写行
function AddSignRow(){
//读取最后一行的行号,存放在txtTRLastIndex文本框中
var txtTRLastIndex = findObj("txtTRLastIndex",document);
var rowID = parseInt(txtTRLastIndex.value);
//alert(txtTRLastIndex.value);
var tbNew = findObj("tbNew",document);
if(parseInt(tbNew.rows.length) < 6)
{
//添加行
var newTR = tbNew.insertRow(tbNew.rows.length);
newTR.id = "SignItem" + rowID;
//添加列:序号
var newNameTD=newTR.insertCell(0);
newNameTD.width ="30";
newNameTD.style.bgcolor ="White";
//添加列内容
newNameTD.innerHTML = newTR.rowIndex.toString();
//添加列:设备类别
var newConfigurationType=newTR.insertCell(1);
newConfigurationType.width ="60";
//添加列内容
newConfigurationType.innerHTML = "<input name='txtConfigurationType" + rowID + "' id='txtConfigurationType" + rowID + "' type='text' size='6' />";
//添加列:设备型号
var newConfigurationScale=newTR.insertCell(2);
newConfigurationScale.width ="60";
//添加列内容
newConfigurationScale.innerHTML = "<input name='txtConfigurationScale" + rowID + "' id='txtConfigurationScale" + rowID + "' type='text' size='6' />";
//添加列:申请数量
var newCountTD=newTR.insertCell(3);
newCountTD.width ="60";
//添加列内容
newCountTD.innerHTML = "<input name='txtCount" + rowID + "' id='txtCount" + rowID + "' type='text' size='6' />";
//添加列:使用人
var newConfigurationUserTD=newTR.insertCell(4);
newConfigurationUserTD.width ="60";
//添加列内容
newConfigurationUserTD.innerHTML = "<input name='txtConfigurationUser" + rowID + "' id='txtConfigurationUser" + rowID + "' type='text' size='6' />";
//添加列:申请原因
var newAppReasonsTD=newTR.insertCell(5);
newAppReasonsTD.width ="60";
//添加列内容
newAppReasonsTD.innerHTML = "<input name='txtAppReasons" + rowID + "' id='txtAppReasons" + rowID + "' type='text' size='6' />";
//添加列:申请类别
var newAppTypeTD=newTR.insertCell(6);
newAppTypeTD.width ="60";