62,272
社区成员
发帖
与我相关
我的任务
分享<!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>
<title>无标题页</title>
<script language="javascript">
function AddNewRow()
{
var table = document.getElementById("mytable");
var row = table.insertRow(table.rows.length);
var col = row.insertCell(0);
col.innerHTML = ' <input name= "txt1 " size= "1 "> ';
col = row.insertCell(1);
col.innerHTML = ' <input name= "txt2 " size= "5 "> ';
col = row.insertCell(2);
col.innerHTML = ' <input type="button" value="添加新行" onclick="AddNewRow();" /> <input name="delBtn" type="button" value="删除此行" onclick="DelRow();" /> ';
}
function DelRow()
{
var srcName = document.getElementsByName("delBtn");
var rowIndex = 0;
for (i=0;i <srcName.length;i++)
{
if(srcName[i]==event.srcElement)
{
rowIndex=i;
}
}
var table = document.getElementById("mytable");
table.deleteRow(rowIndex + 1);
}
</script>
</head>
<body>
<table id="mytable">
<tr>
<td>
111
</td>
<td>
222
</td>
<td>
<input type="button" value="添加新行" onclick="AddNewRow();" />
</td>
</tr>
</table>
</body>
</html>
<input type="button" value="Add" />
<input type="button" value="Delete" />
<table id="testTable">
<tr>
<td>Col1</td>
<td>Col2</td>
<td>Col3</td>
</tr>
</table>
<script src="JS/jquery-1.4.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("input[type='button'][value='Add']").click(function() {
$("<tr><td><input type='text' /></td><td><input type='text' /></td><td><input type='text' /></td></tr>").insertAfter($("#testTable tr:last-child"));
});
$("input[type='button'][value='Delete']").click(function() {
if ($("#testTable tr").length > 1) {
$("#testTable tr:last-child").remove();
}
});
});
</script>
前台:
<asp:Table ID="Table1" runat="server">
</asp:Table>
后台:
TableRow row1;
TableCell cell;
for (int i = 0; i < 10; i++)
{
row1 = new TableRow();
for (int j = 0; j < 3; j++)
{
cell = new TableCell();
TextBox txt = new TextBox();
txt.Text = j.ToString();
txt.ID = i.ToString() + j.ToString();
cell.Controls.Add(txt);
row1.Cells.Add(cell);
}
Table1.Rows.Add(row1);
}