<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>测试</title>
</head>
<body>
<table width="100%" border="1">
  <tr>
    <td id=hrong>&nbsp;</td>
  </tr>
</table>
<script type="text/javascript">
function aa()
{
alert("nodeName = "+ this.nodeName);
}
  document.all.hrong.onclick = aa;
</script>
</body>
</html>

解决方案 »

  1.   

    to: meizz(梅花雪 MVP)
    谢谢,我知道这个可以,不过我不理解我的为什么不行?请你解释一下好吗???
      

  2.   

    对于这个问题我是这样理解的, 不知道我理解的对不对:
    在 onclick="aa()" 这样调用函数aa(),是把这个函数作为 onclick() 方法里的一个语句来执行了, 这里的 this 还是指向函数 aa() 本身. 而hrong.onclick = aa这种写法, onclick 不是调用 aa, 而是把 aa 函数里所有语句全部转给了 onclick ,即中间的 aa 这个环节已经没有了. 后面这种方法还有几种等价的定法:
    function document.all.hrong.onclick(){alert("nodeName = "+ this.nodeName);}
    function document.all.hrong.onclick = function()
    {alert("nodeName = "+ this.nodeName);} //与这个特别象, 可以从这里理解切入点
      

  3.   

    不好意思, 有点错误纠正一下:document.all.hrong.onclick = function() {alert("nodeName = "+ this.nodeName);}
      

  4.   

    谢谢你梅老大,我理解了。
    看你们都答得这么爽,我也来补充一下方法。
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>测试</title>
    <script type="text/javascript">
    function aa(a)
    {
    alert(a.nodeName);
    }
    </script>
    </head>
    <body>
    <table width="100%" border="1">
      <tr>
        <td onClick="aa(this);">&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>
      

  5.   

    to:aotianlong(初中没毕业)
    你的好意我心领啦。谢谢!