http://expert.csdn.net/Expert/topic/2654/2654542.xml?temp=.458111

解决方案 »

  1.   

    http://msdn.microsoft.com/workshop/author/tables/buildtables.asp
    如果你英语好,看看就能懂了table要有id
    var onerow=tableid.insertRow(tableid.rows.length);
    var onecell=onerow.insertCell();
    var twocell=onerow.insertCell();
    var threecell=onerow.insertCell();
    ....
    onecell.innerText="...";//文字
    twocell.innerHTML="...";//HTML元素,也可是文字
    threecell.appendChild(object);//给单元格加对象onerow.attachEvent ('onmouseover', 变色函数名);//上去变色
    onerow.attachEvent ('onmouseout', 恢复函数名);//恢复
      

  2.   

    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <TITLE></TITLE>
    </HEAD>
    <BODY><table id=myTable border=1>
    <tr>
    <td>AAA</td>
    <td>BBB</td>
    <td>CCC</td>
    </tr>
    </table>
    <input type="button" value="add row" onClick="foo()">
    <script>
    function foo(){
    var oTr = myTable.firstChild.firstChild.cloneNode(true);
    myTable.firstChild.appendChild(oTr);
    }
    </script>
    </BODY>
    </HTML>
      

  3.   

    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <TITLE></TITLE>
    </HEAD>
    <BODY><table id=myTable border=1>
    <tr flag="old" onMouseOver="moveOver()" onMouseOut="moveOut()">
    <td>AAA</td>
    <td>BBB</td>
    <td>CCC</td>
    </tr>
    </table>
    <input type="button" value="add row" onClick="foo()">
    <script>
    function foo(){
    var oTr = myTable.firstChild.firstChild.cloneNode(true);
    oTr.flag = "new";
    myTable.firstChild.appendChild(oTr);
    }
    function moveOver(){
    var oTr = event.srcElement;
    while(oTr.tagName != "TR"){
    oTr = oTr.parentElement;
    }
    if(oTr.flag == "new")
    oTr.style.backgroundColor='blue';
    }
    function moveOut(){
    var oTr = event.srcElement;
    while(oTr.tagName != "TR"){
    oTr = oTr.parentElement;
    }
    if(oTr.flag == "new")
    oTr.style.backgroundColor='';
    }
    </script>
    </BODY>
    </HTML>