var td = document.createElement("td");
td.onclick = function(){...};

解决方案 »

  1.   

    可以在td中放一个层,把内容都放在层中,同时对层赋予onclick事件。
      

  2.   

    也可以这么做:
    var td = document.createElement("td"); 
    td.onclick=函数名
    在js中定义并实现该函数就可以了。
      

  3.   

    var _tr=_table.insertRow(i);
    _tr.onmouseout=OU1(this);
    _tr.onmouseover=OV(this);为何不行?
      

  4.   

    _tr.onMouseOver=OV(_tr); 这样的代码可以加入,只有生成接点是有效,以后就不起作用
      

  5.   

    _tr.onmouseout=OU1(this);
    _tr.onmouseover=OV(this); 不需要傳遞this,因為在執行_tr的mouseout和mouseover時,OU1,OV的[[scope]]已經是_tr了。
      

  6.   

    var tdd="<input id='td1' name='td1' onclick="getTDs(\"x_y\");">";
    document.getElementById("div0").innerHTML=tdd;
    这么写绝对没有问题。
      

  7.   

    var td = document.createElement("td"); 
    td.onclick = function(){...};
      

  8.   

    function CreateTable(sParendNode,sNewTableID,sTableText,nCols,nRows,sTableTitle,sTableHead,sTableFoot)
    {
    var container=document.getElementById(sParendNode);
    var _table=document.createElement("table");
    var i,j;
    var _TableTextArray=sTableText.split("|",nRows*nCols);
    nRows=Math.ceil(_TableTextArray.length/nCols);
    container.innerHTML="";
    _table.setAttribute("id",sNewTableID);
    _table.setAttribute("className","TableStyle01");
    //_table.setAttribute("className","mytable");
    //表格标题
    if (sTableTitle!=undefined)
    {
    var _TableTitle=_table.createCaption()
    _TableTitle.setAttribute("className","TableTitleStyle01");
      _TableTitle.innerHTML=sTableTitle;
    }
    //Thead
    // if (sTableHead!=undefined)
    // {
    // var _TableHead=_table.createTHead()
    // _TableHead.setAttribute("className","TableTitleStyle01");
    //   _TableHead.innerHTML=sTableHead;
    // }
    //表格第一行
    for(i=0;i<1;i++)
    {
    var _tr=_table.insertRow(i);
    _tr.setAttribute("id",sNewTableID+"_row_"+i);
    for(j=0;j<nCols;j++)
    {
    var _td=_tr.insertCell(j);
    _td.setAttribute("className","TdTitleStyle01");
    var _tdText=(_TableTextArray[i*nCols+j]==undefined?" ":_TableTextArray[i*nCols+j]);
    _td.innerHTML=_tdText;
    }
    }
    //数据栏
    for(i=1;i<nRows;i++)
    {
    var _tr=_table.insertRow(i);
    _tr.setAttribute("id",sNewTableID+"_row_"+i);
    if (i%2==0)
    {
    _tr.setAttribute("className","TdColorStyle01");
    _tr.onMouseOut=OU1(_tr);
    }
    else
    {
    _tr.setAttribute("className","TdStyle01");
    _tr.onMouseOut=OU2(_tr);
    }
    //_tr.onMouseOver=OV(_tr);
    for(j=0;j<nCols;j++)
    {
    var _td=_tr.insertCell(j);
    var _tdText=(_TableTextArray[i*nCols+j]==undefined?" ":_TableTextArray[i*nCols+j]);
    _td.innerHTML=_tdText;
    }
    }
    //TFoot
    // if (sTableFoot!=undefined)
    // { var _TableFoot=_table.createTFoot()
    //_TableFoot.setAttribute("className","TableTitleStyle01");
    //   _TableFoot.innerHTML=sTableFoot;
    // }
    container.appendChild(_table);
    }为何生成的表格行全是_tr.onMouseOut=OU1(_tr); OU1设置的颜色,并且onMouseOut和onMouseOver 不起效果
      

  9.   

    <html>
    <head>
    </head>
    <body>
    <table width="100%" border="1">
          <tr id="colortr">
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table>
    </body>
    <script type="text/javascript">
    var t=document.getElementById("colortr");
    t.onMouseOut=OU(t);
    t.onMouseOver=OV(t);
    function OV(o)
    { //mouseover
    o.style.backgroundColor='#FFFFCC';
    o.style.color='#0022FF'; 
    o.style.cursor='hand';}
    function OU(o)
    { //mouseout
    o.style.backgroundColor='#FFFFFF';
    o.style.color='#000000';
    }
    </script>
    </html>//为何mouseover mouseout 不起作用
      

  10.   

    javascript是区分大小写的 onMouseOut 和 onmouseout 是 不同的
      

  11.   

    在JS中事件是小写的<html> 
    <head> 
    </head> 
    <body> 
    <table width="100%" border="1"> 
          <tr id="colortr"> 
            <td>&nbsp; </td> 
            <td>&nbsp; </td> 
          </tr> 
        </table> 
    </body> 
    <script type="text/javascript"> 
    var t=document.getElementById("colortr"); 
    t.onmouseout=function(){OU(t)}; 
    t.onmouseover=function(){OV(t)}; 
    //document.getElementById("colortr") = t;
    function OV(o) 
    { //mouseover 
    o.style.backgroundColor='#FFFFCC'; 
    o.style.color='#0022FF'; 
    o.style.cursor='hand'; } 
    function OU(o) 
    { //mouseout 
    o.style.backgroundColor='#FFFFFF'; 
    o.style.color='#000000'; 
    }
    </script> 
    </html>