日期:2014-05-16  浏览次数:20634 次

js 用document.getElementsByName()获取表格数据
我做了个动态添加行,获取其中一行数据保存成一个字符串,但是获取的时候就把整个表格的数据获取了。郁闷,在线等待答案。。。 sub()函数就是获取数据的。

下面是部分代码:
function add_item()
{
   
  var arr = new Array(5)  
  arr[0]="waName";
  arr[1]="waSn";
  arr[2]="waBirth";
  arr[3]="waDep"
  arr[4]="waSec";
   
   
  


  var table=document.getElementById("power");
  var rows=table.rows.length-1;
  var newrow=table.insertRow(rows+1);
  var num=rows+n;
   
  for (var i=0;i<table.rows[0].cells.length;i++)
{
the_cell=newrow.insertCell(i);

if(arr[i]=="waName")
the_cell.innerHTML="<center><input type='text' name='column' id='waName' value='waName' size='8' />&nbsp;<input type='button' value='查找' style='cursor:hand' onclick='openEmployeeControl()'></center> ";

else if(arr[i]=="waSn")
the_cell.innerHTML="<center><input type='text' name='column' id='waSn' value='waSn' size='8' /></center> ";

else if(arr[i]=="waBirth")
the_cell.innerHTML="<center><input type='text' name='column' id='waBirth' value='' size='10'/></center> ";

else if(arr[i]=="waDep")
the_cell.innerHTML="<center><input type='text' name='column' id='waDep' value='' size='10'/></center> ";

else if(arr[i]=="waSec")
the_cell.innerHTML="<center><input type='text' name='column' id='waSec' value='' size='10'/></center> ";
 

}
 

}
function sub()
{
  var pri = "";
var form = document.WageeFormBean;
var columnobj=document.getElementById("power");

for(var i=0;i<columnobj.rows.length-1;i++)

window.alert("hj") ;
 
var obj_sub =document.getElementsByName("column");  
 
if(obj_sub.length != null)
{
var subpri = "";
for(var t=0;t<obj_sub.length;t++)
{
if(obj_sub[t].value!="")
{
subpri = subpri + obj_sub[t].value+ ",";
}
   
  }
  window.alert("ggg") ;
  }
   
  pri =pri +subpri;
  pri = pri + ";";
}
   
document.getElementById("waPri").value = pri;  
}

<table width="3000" border="1" id="power" align="center" cellpadding="3" cellspacing="1"bordercolor="#799AE1" class="style1">
  
 <tr>
  <td align="center" width="25"><html:text property="coName" value="姓名" size="16" ></html:text></td>
   
  <td align="center" width="35"><html:text property="coSn" value="员工号" size="8" ></html:text></td>
   
  ....


</tr>
 
</table>


------解决方案--------------------
var obj_sub =