client side event??<table id=tbl>
</table><input type=button value=add onclick="addRow()"><script language="javascript">
function addRow()
{
var row = tbl.insertRow();
row.onclick = function () { alert(this.rowIndex + "n" + this.innerHTML);} var cell = row.insertCell();
cell.innerText = new Date();
cell = row.insertCell();
cell.innerText = new Date();
}
</script>
</table><input type=button value=add onclick="addRow()"><script language="javascript">
function addRow()
{
var row = tbl.insertRow();
row.onclick = function () { alert(this.rowIndex + "n" + this.innerHTML);} var cell = row.insertCell();
cell.innerText = new Date();
cell = row.insertCell();
cell.innerText = new Date();
}
</script>
<form id="Form1" method="post" runat="server">
<asp:Table id="Table1" runat="server"></asp:Table>
</form>
</body>
protected System.Web.UI.WebControls.Table Table1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
System.Web.UI.WebControls.TableRow DR = new System.Web.UI.WebControls.TableRow();
System.Web.UI.WebControls.TableCell TC = new System.Web.UI.WebControls.TableCell();
TC.Text = "aaaa";
DR.Controls.Add(TC);
DR.Attributes["onclick"]="JavaScript:alert(\"您单击了第一行\");";
Table1.Rows.Add(DR);
}
我用的是HTML控件table,不是服务器端控件。我要用Javascript动态的加入一行。
思归的方法应该是可以的,可是我调试老是不成功。
谢谢思归。
这个问题可能对大家有时会有点帮助。
让大家看看我就结贴!
var i = 0;
var nowRow = null;
function trSelect()
{
if(nowRow != null)
nowRow.style.background="#dff3fb";
this.style.background = "#A5baf7";
nowRow = this;
}
function trDblClick()
{
if(nowRow != null)
alert("双击了");
}
function addRow()
{
i = i + 1;
var newRow = document.all("Table1").insertRow();
newRow.style.height = "25";
newRow.style.backgroundColor = "#DFF3FB";
newRow.onclick = trSelect;
newRow.ondblclick = trDblClick;
newRow.align ="center";
newRow.style.cursor = "hand";
//构造页面表格的界面显示
var newCell = newRow.insertCell();
newCell.innerHTML = "Hello";
newCell = newRow.insertCell();
newCell.innerHTML = "world";
}
</script>
<body>
<form id=form1>
<input type=button onclick="addRow()" id="btnAdd" value="添加行">
<table id="Table1" borderColor="#dff3fb" cellSpacing="0" cellPadding="0" width="100%" border="1">
<tr bgcolor="green">
<td>列1</td>
<td>列2</td>
</tr>
</table>
</form>
</body>