<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function addrow()
{
var tr=document.all.item('showTable').insertRow();
for(var i=0;i<3;i++)
{
the_cell=tr.insertCell(i);
the_cell.innerText="NewRow_" + the_cell.parentElement.rowIndex;
}
tr.onclick= function(){doalter();}; //没有效果
}
function doalter(){
alert('hi');
}
//-->
</SCRIPT>
<table id="showTable">
</table>
<input type=button value=add onclick="addrow()">
</BODY>
</HTML>
动态加入table中tr的onclick事件
最新推荐文章于 2023-07-05 09:25:09 发布
本文介绍了一个使用JavaScript实现的简单表格操作示例,通过点击按钮可以向表格中添加新行,并为新添加的行设置点击事件。该示例展示了如何利用DOM操作来动态创建表格元素,并附带简单的交互功能。

9137

被折叠的 条评论
为什么被折叠?



