首页 > 代码库 > DOM(七)使用DOM控制表格

DOM(七)使用DOM控制表格

1.插入一行

 

<script type="text/javascript">window.onload=function(){    var oTr = document.getElementById("member").insertRow(2);    //插入一行    var aText = new Array();    aText[0] = document.createTextNode("fresheggs");    aText[1] = document.createTextNode("W610");    aText[2] = document.createTextNode("Nov 5th");    aText[3] = document.createTextNode("Scorpio");    aText[4] = document.createTextNode("1038818");    for(var i=0;i<aText.length;i++){        var oTd = oTr.insertCell(i);        oTd.appendChild(aText[i]);    }}</script><table class="datalist" summary="list of members in EE Studay" id="member">    <caption>Member List</caption>    <tr>        <th scope="col">Name</th>        <th scope="col">Class</th>        <th scope="col">Birthday</th>        <th scope="col">Constellation</th>        <th scope="col">Mobile</th>    </tr>    <tr>        <td>isaac</td>        <td>W13</td>        <td>Jun 24th</td>        <td>Cancer</td>        <td>1118159</td>    </tr>    <tr>        <td>girlwing</td>        <td>W210</td>        <td>Sep 16th</td>        <td>Virgo</td>        <td>1307994</td>    </tr>    <tr>        <td>tastestory</td>        <td>W15</td>        <td>Nov 29th</td>        <td>Sagittarius</td>        <td>1095245</td>    </tr></table>

 

DOM(七)使用DOM控制表格