动态添加表格(增加事件)
2007-06-07 09:52
459 查看
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body onLoad="addRow()">
<table width="33%" border=1 id="testTbl">
<tr id="tr1">
<td width=6%><input type=checkbox id="box1"></td>
<td id="b">第一行</td>
</tr>
<tr id="tr2">
<td width=6%><input type=checkbox id="box2"></td>
<td id="b">第二行</td>
</tr>
<tr bgcolor=#0000FF>
<td width=6%><input type=checkbox id="box3"></td>
<td>第三行</td>
</tr>
<input type="button" onClick="addRow()" value="Add"/>
</table>
</body>
<script>
function Test(obj){
alert(obj.id);
}
function addRow(){
for(var j=0;j<10;j++){
var newTr = testTbl.insertRow();
var newTd = newTr.insertCell();
newTd.bgColor="white";
newTd.style.cursor="pointer";
newTd.id=j;
newTr.id=j;
newTd.height="16";
newTd.align="center";
newTd.innerHTML="AAAA";
newTr.setAttribute('oncontextmenu',function(){Test(this)});
//newTd.attachEvent('oncontextmenu', function(){alert(newTd.id);});
//newTr.oncontextmenu=Test;
//newTd.setAttribute("onClick","Test()");
//newTd.onClick="alert(/'"+newTd.id+"/')";
alert(newTr.innerHTML);
}
}
</script>
</body>
</html>
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body onLoad="addRow()">
<table width="33%" border=1 id="testTbl">
<tr id="tr1">
<td width=6%><input type=checkbox id="box1"></td>
<td id="b">第一行</td>
</tr>
<tr id="tr2">
<td width=6%><input type=checkbox id="box2"></td>
<td id="b">第二行</td>
</tr>
<tr bgcolor=#0000FF>
<td width=6%><input type=checkbox id="box3"></td>
<td>第三行</td>
</tr>
<input type="button" onClick="addRow()" value="Add"/>
</table>
</body>
<script>
function Test(obj){
alert(obj.id);
}
function addRow(){
for(var j=0;j<10;j++){
var newTr = testTbl.insertRow();
var newTd = newTr.insertCell();
newTd.bgColor="white";
newTd.style.cursor="pointer";
newTd.id=j;
newTr.id=j;
newTd.height="16";
newTd.align="center";
newTd.innerHTML="AAAA";
newTr.setAttribute('oncontextmenu',function(){Test(this)});
//newTd.attachEvent('oncontextmenu', function(){alert(newTd.id);});
//newTr.oncontextmenu=Test;
//newTd.setAttribute("onClick","Test()");
//newTd.onClick="alert(/'"+newTd.id+"/')";
alert(newTr.innerHTML);
}
}
</script>
</body>
</html>
相关文章推荐
- JQuery实现表格动态增加行并对新行添加事件
- JQuery实现表格动态增加行并对新行添加事件
- js动态往表格的td中添加图片并注册事件
- JS动态创建表格,动态设置属性,动态添加事件
- ASP.NET页面中动态增加的控件、添加事件
- JS动态创建表格,动态设置属性,动态添加事件
- js为动态添加的元素增加事件(事件委托)
- JSP页面动态生成表格并为表格添加事件(续)
- 表格动态加,删除行 单元格元素添加点击事件
- [转] JavaScript 动态添加表格/动态添加事件/态设置属性
- JQuery实现表格自动增加行,对新行添加事件
- js为动态添加的元素增加事件(事件委托)
- 给动态增加的元素添加事件
- JS实现为动态添加的元素增加事件功能示例【基于事件委托】
- easy-ui中表格中动态添加checkbox,和全选事件和判断选中事件
- js生成动态表格并为每个单元格添加单击事件的方法
- 动态给表格TD 添加单击事件
- jQuery动态增加表格,增加行,并添加ID
- JSP页面动态生成表格并为表格添加事件
- ASP.NET 页面中动态增加的控件、添加事件第1/2页