日期:2014-05-16  浏览次数:20397 次

表格内容的动态填充
HTML code
<table width="200" border="1">
  <tr>
    <td>aaa</td>
    <td>bbb</td>
    <td>cccc</td>
  </tr>
  <tr>
    <td>111</td>
    <td>222</td>
    <td>333</td>
  </tr>
  <tr>
    <td>rrf</td>
    <td>ssa</td>
    <td>gtt</td>
  </tr>
</table>


用JS实现表格单元格内容的动态呈现,即依此填充单元格内容,能否实现?

------解决方案--------------------
HTML code

<table width="200" border="1" id="tab">
</table>
<SCRIPT LANGUAGE="JavaScript">
<!--
    var arr = [];
    arr[arr.length] = ["aaa","bbb","cccc"];
    arr[arr.length] = ["111","222","333"];
    arr[arr.length] = ["rrf","ssa","gtt"];

    var tab = document.getElementById("tab");
    for (var i=0; i<arr.length; i++)
    {
        var newrow = tab.insertRow();
        for (var j=0; j<arr[i].length; j++)
        {
            var newcell = newrow.insertCell();
            newcell.innerHTML = arr[i][j];
        }
    }
//-->
</SCRIPT>