如何一次性给页面中的表格所有单元格添加同一个事件 <script language="javascript">for(i=0; i<document.getElementsByTagName("div").length;i++){ table=document.getElementsByTagName("div")[i]; for(j=0;j<table.cells.length;j++) { table.cells.onclick=..; }}</script>应该可以把不知道有没有更好的方法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script language="javascript">for(i=0; i<document.getElementsByTagName("table").length;i++){ table=document.getElementsByTagName("table")[i]; for(j=0;j<table.cells.length;j++) { table.cells[j].onclick=..; }}</script> 怎么回不行呢包的什么错另外function show(obj){alert(obj.value)} 有问题td没有value属性 for(i=0;j<document.getElementsByTagName("tb");i++) { document.getElementsByTagName("tb")[i].onclick=..; }这个也行 不用给所有td加上事件,给table加上事件就可以了<!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body><table border="1" onclick="fun(arguments)"> <tr> <td>1:1</td> <td>1:2</td> </tr> <tr> <td>2:1</td> <td>2:2</td> </tr></table><script type="text/javascript">function fun(arg){ var evt = window.event || arg[0]; var el = evt.target || evt.srcElement; if(el.tagName.toLowerCase()=="td") alert(el.innerHTML);}</script></body></html> for(i=0;i<document.getElementsByTagName("td").length;i++) { document.getElementsByTagName("td")[i].onclick} 又搞错了 <html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>新建网页 1</title></head><body><script language="javascript">function show(){alert(this.innerHTML);}document.write("<table border=1>");for(i=0;i<9;i++){ document.write("<tr>"); for(j=0;j<9;j++) document.write("<td>"+i+","+j+"</td>"); document.write("</tr>");}document.write("</table>");for(i=0;i<document.getElementsByTagName("td").length;i++) { document.getElementsByTagName("td")[i].onclick=show; } </script></body></html>10的也行。。 FF下如何动态获取或者是设置z-index啊???????????? js 提交后不能自动关闭 jsp:useBean定义的对象不能在页面的函数中使用 javascript中的sort方法怎么实现稳定排序 一段简单的代码怎么就出错了? web页读excel文件?!乱码!--sos求救 怎样在IE窗口中限制鼠标在只能在一定区域中活动 复选框可以美化吗? 請問在一個頁面如何調用另外一個頁面的過程并執行它﹐那個過程是用vbscript寫的。 哪位给解释一下这段代码的功能 下面代码如何控制表格各单元格同时放大多少倍 如何实现n个input同步输入?
<script language="javascript">
for(i=0; i<document.getElementsByTagName("table").length;i++)
{
table=document.getElementsByTagName("table")[i];
for(j=0;j<table.cells.length;j++)
{
table.cells[j].onclick=..;
}
}
</script>
包的什么错
另外
function show(obj){alert(obj.value)} 有问题
td没有value属性
{
document.getElementsByTagName("tb")[i].onclick=..;
}
这个也行
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body><table border="1" onclick="fun(arguments)">
<tr>
<td>1:1</td>
<td>1:2</td>
</tr>
<tr>
<td>2:1</td>
<td>2:2</td>
</tr>
</table>
<script type="text/javascript">
function fun(arg)
{
var evt = window.event || arg[0];
var el = evt.target || evt.srcElement;
if(el.tagName.toLowerCase()=="td")
alert(el.innerHTML);
}
</script>
</body>
</html>
{
document.getElementsByTagName("td")[i].onclick
}
又搞错了
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body>
<script language="javascript">
function show()
{
alert(this.innerHTML);
}document.write("<table border=1>");
for(i=0;i<9;i++)
{
document.write("<tr>");
for(j=0;j<9;j++)
document.write("<td>"+i+","+j+"</td>");
document.write("</tr>");
}
document.write("</table>");
for(i=0;i<document.getElementsByTagName("td").length;i++)
{
document.getElementsByTagName("td")[i].onclick=show;
}
</script>
</body>
</html>10的也行。。