cell.onmouseout=function(){ this.className="today"; }
这个可以运行。但下面那个把函数写在其他地方
cell.onmouseover=test();
function test(){this.className="today"; }
这样就不行了?

解决方案 »

  1.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>New Page 2</title>
    </head><body>
      <table border="1" width="251" height="181" id=tableid >
        <tr>
          <td width="121" height="47">1</td>
          <td width="114" height="47">2</td>
        </tr>
        <tr>
          <td width="121" height="122">3</td>
          <td width="114" height="122">mouseout</td>
        </tr>
      </table>
    </body></html>
    <script>
    var tablecon = tableid;
    var cell = tablecon.rows[1].cells[1];cell.onmouseover=function(){ this.innerText="mouseover"; }cell.onmouseout=function(){ this.innerText="mouseout"; }
    //cell.onmouseover=test();
    //function test(){this.className="today"; }//这样写的话,this指代的是本函数,而不是cell,所以不行</script>
      

  2.   

    用 cell.attachEvent("onmouseout",funName)
      

  3.   

    //cell.onmouseover=test();
    //function test(){cell.className="today"; }//这样写的话,this指代的是本函数,而不是
    还是不行。cell.attachEvent("onmouseout",funName)
    这个可以,但不管鼠标移出什么地方总是最下面的一个表格被改了颜色。
      

  4.   

    分開寫后this代表的對象已經變了
      

  5.   

    注册两个行不行?
    cell.attachEvent("onmouseout",funName)
    cell.attachEvent("onmouseover",funName2)
      

  6.   

    cell.attachEvent("onmouseout",funName)
    cell.attachEvent("onmouseover",funName2)
    这个还是光改变最后一个表格的颜色,是不是每次总是传一样的值造成的。怎样给funName函数传递值呢?
    cell.attachEvent("onmouseout",funName(1))这样就不行,该如何呢?