<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!--
function MouseOver(obj)
{
obj.style.color = "red"
obj.style.cursor = "hand"
}function MouseOut(obj)
{
obj.style.color = "black"
obj.style.cursor = ""
}
//-->
</script>
</head><body>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr> 
<td onMouseOver="MouseOver(this)" onMouseOut="MouseOut(this)">AAAAAAAA</td>
</tr>
<tr> 
<td onMouseOver="MouseOver(this)" onMouseOut="MouseOut(this)">AAAAAAAAAAAAAAAAAAAA</td>
</tr>
<tr> 
<td onMouseOver="MouseOver(this)" onMouseOut="MouseOut(this)">AAAAAAAAAAAAAAAAAAAAAAAAAA</td>
</tr>
</table>
</body>
</html>

解决方案 »

  1.   

    动态给CELL付函数值怎么写在ADDROW()里
      

  2.   

    这段代码是动态添加表格的。
    <html>
    <head>
    <title>动态添加表格内容</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language="JavaScript">
    <!--
    function InsertRow(strID)
    {
        var obj, objRows, objCells
        var lngTDs
        var i    obj = document.getElementById(strID)
        lngTDs = obj.rows(0).cells.length    objRows = obj.insertRow()
        for (i=0; i<lngTDs; i++) {
            objCells = objRows.insertCell()
            objCells.innerHTML = "test"
        }
    }function InsertCell(strID)
    {
        var obj, objCells
        var lngTRs
        var i    obj = document.getElementById(strID)
        lngTRs = obj.rows.length    for (i=0; i<lngTRs; i++) {
            objCells = obj.rows(i).insertCell()
            objCells.innerHTML = "test"
        }
    }function MouseOver(obj)
    {
        obj.style.color = "red"
        obj.style.cursor = "hand"
    }function MouseOut(obj)
    {
        obj.style.color = "black"
        obj.style.cursor = ""
    }
    //-->
    </script>
    </head><body>
    <a href="javascript: InsertRow('tblEx')">INSERT&nbsp;TR</a>&nbsp;&nbsp;<a href="javascript: InsertCell('tblEx')">INSERT&nbsp;TD</a><br>
    <table width="100%" border="1" cellspacing="0" cellpadding="0" id="tblEx">
        <tr> 
            <td onMouseOver="MouseOver(this)" onMouseOut="MouseOut(this)">AAAAAAAA</td>
            <td onMouseOver="MouseOver(this)" onMouseOut="MouseOut(this)">&nbsp;</td>
        </tr>
        <tr> 
            <td onMouseOver="MouseOver(this)" onMouseOut="MouseOut(this)">AAAAAAAAAAAAAAAAAAAA</td>
            <td onMouseOver="MouseOver(this)" onMouseOut="MouseOut(this)">&nbsp;</td>
        </tr>
        <tr> 
            <td onMouseOver="MouseOver(this)" onMouseOut="MouseOut(this)">AAAAAAAAAAAAAAAAAAAAAAAAAA</td>
            <td onMouseOver="MouseOver(this)" onMouseOut="MouseOut(this)">&nbsp;</td>
        </tr>
    </table>
    </body>
    </html>
      

  3.   

    没有理解我的意识,可能我的说法不准确,同样谢谢。
    我想的到的结果是把onMouseOver或其他函数在动态加CELL时候如何付给CELL
      

  4.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    </HEAD>
    <script>
    function InsertRow()
    {
      var tbl = document.getElementById("tbl");
      var tr = tbl.insertRow();
    }
    function InsertCell(strID)
    {
      var tbl = document.getElementById("tbl");
      if (tbl.rows.length)
      {
        var tr = tbl.rows[tbl.rows.length-1];
        if (tr)
        {
          var td = tr.insertCell();
          td.innerHTML = "Cell" + tr.cells.length;      td.onmouseover = function ()
          {
            this.style.cursor = "hand";
            this.style.color = "#FF0000";
          }      td.onmouseout = function ()
          {
            this.style.color = "#000000";
          }
        }
      }
    }
    </script><BODY>
    <table width="100%" border="1" cellspacing="0" cellpadding="0" id="tbl">
    </table>    
    <input type="button" value="InsertRow" onclick="InsertRow()">
    <input type="button" value="InsertCell" onclick="InsertCell()">
    </BODY>
    </HTML>
      

  5.   

    我刚刚修改后的
    <html>
    <head>
    <title>动态添加表格内容</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language="JavaScript">
    <!--
    function InsertRow(strID)
    {
        var obj, objRows, objCells
        var lngTDs
        var i    obj = document.getElementById(strID)
        if (obj.rows.length == 0) {
            lngTDs = 1
        }
        else {
            lngTDs = obj.rows(0).cells.length
        }    objRows = obj.insertRow()
        for (i=0; i<lngTDs; i++) {
            InsertTD(objRows)
        }
    }function InsertCell(strID)
    {
        var obj, objCells
        var lngTRs
        var i    obj = document.getElementById(strID)
        lngTRs = obj.rows.length    for (i=0; i<lngTRs; i++) {
            InsertTD(obj.rows(i))
        }
    }function InsertTD(obj)
    {
        var objCells    objCells = obj.insertCell()
        objCells.innerHTML = "test " + Math.floor(Math.random() * 10000)
        objCells.align = "center"    objCells.onmouseover = function()
        {
            this.style.color = "red"
            this.style.cursor = "hand"
        }
        objCells.onmouseout = function()
        {
            this.style.color = "black"
            this.style.cursor = ""
        }
    }
    //-->
    </script>
    </head><body>
    <a href="javascript: InsertRow('tblEx')">INSERT&nbsp;TR</a>&nbsp;&nbsp;<a href="javascript: InsertCell('tblEx')">INSERT&nbsp;TD</a><br>
    <table width="100%" border="1" cellspacing="0" cellpadding="0" id="tblEx">
    </table>
    </body>
    </html>
      

  6.   

    谢谢!
    <script>
       function aa();
    </script>
    objCells.onmouseover =aa();
    可以吗?
      

  7.   

    我昨天试的时候,如果函数带参数,则不行。建议你使用 zhanghk 的方法。看看MSDN中关于这部分的帮助吧,我也是看到你的问题后,边看帮助边写的。