你说的自动生成<td></td>,是用什么形式来生成的?

解决方案 »

  1.   

    obj.onmouseover=function (){
     this.style.backgroundColor='black';
    }
    obj.onmouseout=function (){
     this.style.backgroundColor='white';
    }
      

  2.   

    <!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=gb2312" />
    <title>setAttribute</title>
    <style type="text/css">
    .tt {
    width:100px;
    height:50px;
    border:#666 1px solid;
    line-height:50px;
    text-align:center;
    background:#ff0;
    }
    .ttover {
    width:100px;
    height:50px;
    border:#666 1px solid;
    line-height:50px;
    text-align:center;
    background:#f00;
    }
    .ttout {
    width:100px;
    height:50px;
    border:#666 1px solid;
    line-height:50px;
    text-align:center;
    background:#ccc;
    }
    </style>
    </head>
    <body>
    <div id="d1" class="tt">aaa</div>
    <button onclick="xlh()">添加属性</button>
    <script type="text/javascript" defer="defer">
      var dd = document.getElementById("d1");
     function xlh(){
    dd.setAttribute("onmouseover",over);
    dd.setAttribute("onmouseout",out);
     }
     function over(){
    dd.className = "ttover";
     }
     function out(){
      dd.className = "ttout";
     }
    </script>
    </body>
    </html>