<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>
应该可以把不知道有没有更好的方法

解决方案 »

  1.   


    <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>
      

  2.   

    怎么回不行呢
    包的什么错
    另外
    function show(obj){alert(obj.value)} 有问题
    td没有value属性
      

  3.   

        for(i=0;j<document.getElementsByTagName("tb");i++)
        {
           document.getElementsByTagName("tb")[i].onclick=..;
        }
    这个也行
      

  4.   

    不用给所有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>
      

  5.   

    for(i=0;i<document.getElementsByTagName("td").length;i++) 

    document.getElementsByTagName("td")[i].onclick

    又搞错了
      

  6.   


    <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的也行。。