日期:2014-05-18 浏览次数:20540 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script>
function AddRow()
{
var tname = document.getElementById("t_x1").value;
for(var i =1;i<=tname;i++)
{
var newTr = customers.insertRow();
var newTd = newTr.insertCell();
newTd.innerHTML = '<input type="text" id="t_b1' + i + '" name="t_b1' + i + '"/>';
newTd = newTr.insertCell();
newTd.innerHTML = '<input type="submit" id="box" value="删除" onclick="removeRow()" />';
}
}
function removeRow()
{
var rowIndex = event.srcElement.parentElement.parentElement.rowIndex;
var styles = document.getElementById("customers");
styles.deleteRow(rowIndex);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="customers">
<tr>
<th colspan="6" style="text-align: left;">
添加行数:<input id="t_x1" type="text" />
<input type="button" value="添加行" onclick="javascript:AddRow();" />
<asp:Button ID="Button1" runat="server" Text="添加" OnClick="Button1_Click" /></th>
</tr>
<tr>
<th>
名字</th>
<th>
管理</th>
</tr>
</table>
</div>
</form>
</body>
</html>
protected void Button1_Click(object sender, EventArgs e)
{
int j = 1;
while (j > 0)
{
if (Request.Form["t_b1" + j] != null)
{
//执行插入数据库。。省略
j++;
}
}
}