1.表格操作的例子太多了,insertRow,appendChild等方法都可以,去搜搜吧.
http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/table.asp2.document.getElementById("tableID").rows[i].cells[j].innerHTML(or innerText)

解决方案 »

  1.   

    1.表格操作的例子太多了,insertRow,appendChild等方法都可以,去搜搜吧.
    http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/table.asp我是在JSP中使用的,能给个例子吗
      

  2.   

    跟是不是jsp没关系
    <script language="JavaScript">
    <!--
    function addRow(){
    with(document.getElementById("demo").firstChild)
    appendChild(firstChild.cloneNode(true));
    }
    //-->
    </script>
    <table id=demo>
    <tr>
    <td><input></td>
    <td><input></td>
    </tr>
    </table>
    <input type=button value="add" onclick="addRow()">
      

  3.   

    楼主问的是JSP还是JavaScript?
    如果是前者,请到JSP板块发帖。
    如果是后者,答案在这里:
    http://msdn.microsoft.com/library/default.asp?url=/workshop/author/tables/buildtables.asp
      

  4.   

    下面的这个例子详细介绍了怎么样增加一行,删除一行,上移一行,下移一行 。 。 。查看某行某列的值:<%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <style>
    .RTable
    {
       background-color:#000000;
       border:3px #CC00FF groove;
       align:center;
       display:"block";
    }
    .RTdNormal
    {
       background-color:#FF0000;
       border: 1px #000000 solid;
    }
    .RTdRussia
    {
       background-color:#00FF00;
       border:1px #CCCCCC solid;
    }
    </style>
    </head><body onkeydown="KeyDown()">
    <table id="RussiaTable" class="RTable" align="center" cellpadding="1" cellspacing="0">
    </table><table id="MyTD" onClick="clickontb()" border="1px #000000 solid" style="font-size:12px;cursor:hand">
    <tr>
    <td>1111111111</td>
    <td>1111122222</td>
    </tr>
    <tr>
    <td>2222211111</td>
    <td>2222222222</td>
    </tr>
    <tr>
    <td>3333311111</td>
    <td>3333322222</td>
    </tr>
    <tr>
    <td>4444411111</td>
    <td>4444422222</td>
    </tr>
    </table>
    <button onClick="AddRow()">添加一行</button>
    <button onClick="DelRow()">删掉一行</button>
    <button onClick="MoveUp()">上移一行</button>
    <button onClick="MoveDown()">下移一行</button>
    <button onClick="ViewValue();">查看选择的表格值</button>
    <script>
    var curRow,colIndex;
    function AddCell(obj)
    {
       if(MyTD.rows[0])
       {
          for(var i = 0  ; i < MyTD.rows[0].cells.length ;i ++)
          {
          var newTd = document.createElement("td");
      newTd.innerText = "新增";
      obj.appendChild(newTd);
      }
       }
    }
    function AddRow()
    {
       var newTr = document.createElement("tr");
       if(MyTD.rows[curRow])
       {
          oldTr = MyTD.rows[curRow] ;
       }
       else
          oldTr = null;
       AddCell(newTr);
       MyTD.children[0].insertBefore(newTr,oldTr);
    }
    function DelRow()
    {
       if(MyTD.rows[curRow])
       {
          oldTr = MyTD.rows[curRow] ;
       }
       else
          oldTr = null;
       MyTD.children[0].removeChild(oldTr);
    }
    function MoveUp()
    {
       if(MyTD.rows[curRow - 1] && MyTD.rows[curRow])
       {
           var insertRow = MyTD.rows[curRow] ;
       var posRow    = MyTD.rows[curRow - 1] ;
           MyTD.children[0].insertBefore(insertRow,posRow);
       curRow -- ;
       }
    }
    function MoveDown()
    {
       if(MyTD.rows[curRow + 1] && MyTD.rows[curRow])
       {
           var insertRow = MyTD.rows[curRow] ;
       var posRow    = insertRow.nextSibling ;
       posRow        = posRow.nextSibling;
           MyTD.children[0].insertBefore(insertRow,posRow);
       curRow ++ ;
       }
    }
    function clickontb()
    {
       src    = event.srcElement;
       if(MyTD.rows[curRow])
       {
           MyTD.rows[curRow].style.backgroundColor = "#FFFFFF";
       }
       curRow = src.parentElement.sectionRowIndex ;
       colIndex = src.cellIndex;
       if(MyTD.rows[curRow] )
       {
           MyTD.rows[curRow].style.backgroundColor = "#FF0000";
       }
    }
    function ViewValue()
    {
     if(MyTD.rows[curRow] && MyTD.rows[curRow].cells[colIndex])
     {
        str = "您刚才点击的是表格的第" + curRow + "行 ,第" + colIndex + "列 ,值为:" + MyTD.rows[curRow].cells[colIndex].innerText;
    alert(str);
     }  else
          alert("你没有点击表格!!");
    }
    </script>
    </body>
    </html>