<script language=javascript> var i=0; var rowIndex=12; function AddRow() { oTR1 = table1.insertRow(rowIndex);
oTD1 = oTR1.insertCell(0); oTD2 = oTR1.insertCell(0); oTD3 = oTR1.insertCell(0); oTD4 = oTR1.insertCell(0);
oTD1.innerHTML = " <input type=text name=name" + i + ">"; oTD2.innerHTML = " <input type=text name=num" + i + ">"; oTD3.innerText = " <input type=text name=post" + i + ">"; oTD4.innerText = " <input type=text name=type" + i + ">"; i++; rowIndex++; }
function ReadValue() { var info = ""; var objInfo = document.getElementsByID("txtInfo"); // txtInfo是服务器控件 for(j=0; j<i; j++) { var temp = ""; var objname = document.all("name"+j); var objnum = document.all("num"+j); var objpost = document.all("post"+j); var objtype = document.all("type"+j); temp = temp + objname.value +"\\" + objnum.value +"\\" +objpost.value +"\\" +objtype.value; info = info + temp; } objInfo.value = info; }
function deleteRow() { rowIndex--; i--; table1.deleteRow(rowIndex); }
在C#代码中用 string[] str=TextBox1.Text.Split("\\") ; 取出分隔好的字符串。
注:将txtInfo的visible不能设为false,否则javascript无法读取,如用<type=hidden> C#无法读取,我的做法是:将txtInfo的width与height设为0,bordercolor设为背景色。
|