日期:2014-05-17  浏览次数:20435 次

取table里面的值
在点击添加行按钮时,用js添加table的一行,代码如下
 //添加行
  function AddHang() {
  var tb = document.getElementById("mytableid");
  var rnum = tb.rows.length;
  var row = tb.insertRow(rnum);
  var cell = row.insertCell(0);
  cell.innerHTML = "<asp:Label style='width: 95%' ID='lbl'" + rnum + ">" + rnum + "</asp:Label>";
  cell = row.insertCell(row.cells.length);
  cell.innerHTML = "<input type='text' style='width:95%' id='ipttime" + rnum + "' onclick='WdatePicker();'>";
  cell = row.insertCell(row.cells.length);
  cell.innerHTML = "<input type='text' style='width:95%' id='iptchu" + rnum + "'>";
  cell = row.insertCell(row.cells.length);
  cell.innerHTML = "<input type='text' style='width:95%' id='iptbao" + rnum + "'>";
  cell = row.insertCell(row.cells.length);
  cell.innerHTML = "<input type='text' style='width:91%' class='show' onchange='Sumjin(this);' id='iptjine" + rnum + "'>";
  cell = row.insertCell(row.cells.length);
  cell.innerHTML = "<input type='text' style='width:95%' id='iptdui" + rnum + "'>";
  cell = row.insertCell(row.cells.length);
  cell.innerHTML = "<input type='text' style='width:95%' id='iptbei" + rnum + "'>";
  cell = row.insertCell(row.cells.length);
  cell.innerHTML = "<a href='#' id='del" + rnum + "' onclick='Del();'>X</a>";
  }
我在里面填入值后,在后台怎么得到写入的值啊

------解决方案--------------------
js里面不能使用服务器控件的

cell.innerHTML = "<input type='text' style='width:95%' id='iptchu" + rnum + "'>";
改成
cell.innerHTML = "<input type='text' style='width:95%' name='iptchu" + rnum + "'>";


然后在提交按钮里面加
<input type="hidden" name="rownum" value= "0" />

后台
int rowNum = Int32.Parse(Request.Params.Get("rownum"))
for(int i=0;i<rowNum ;i++)
Request.Params.Get("iptchu" + i)

就可以得到了