城市獵人

          在一網(wǎng)情深的日子里,誰(shuí)能說(shuō)得清是苦是甜,只知道確定了就義無(wú)反顧
          posts - 1, comments - 7, trackbacks - 0, articles - 89

          動(dòng)態(tài)增加、減少表格

          Posted on 2008-08-05 22:54 sailor 閱讀(269) 評(píng)論(0)  編輯  收藏 所屬分類: javascript

          <html>
          <meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
          <head>

          <script language="javascript">
            function deleteRow(index){
              var tableObj=document.getElementById("mainBody");
              var rowObj=document.getElementById('row'+index);

              tableObj.removeChild(rowObj);

            }
            function addRow(){
               var tableObj=document.getElementById("mytable");
               var tableBodyObj=document.getElementById("mainBody");
               var newRowObj=document.createElement("tr");
               newRowObj.id="row"+(tableObj.rows.length-1);
              
               var newColName=document.createElement("td");
               var newColAge=document.createElement("td");
               var newColButton=document.createElement("td");
              
               newColName.innerHTML=document.getElementById("newName").value;
               newColAge.innerHTML=document.getElementById("newAge").value;
               newColButton.innerHTML='<input type="button" value="刪除" onclick="deleteRow('+(tableObj.rows.length-1)+')">';
              
               newRowObj.appendChild(newColName);
               newRowObj.appendChild(newColAge);
               newRowObj.appendChild(newColButton);
              
               tableBodyObj.appendChild(newRowObj);
              
            }
          </script>
          </head>

          <body>
          <table width="100%" id="mytable" border="0" cellspacing="0" cellpadding="0">
           <tbody id="mainBody">
            <tr>
              <td>姓名</td>
              <td>年齡</td>
              <td>操作</td>
            </tr>
            <tr id="row0">
              <td>gaoxiang</td>
              <td>28</td>
              <td><input type="button" onclick="deleteRow(0)" value="刪除"/></td>
            </tr>
             <tr id="row1">
              <td>gaoxiang</td>
              <td>28</td>
              <td><input type="button" onclick="deleteRow(1)" value="刪除"/></td>
            </tr>
            </tbody>
          </table>

          <input type="text" name="name" id="newName" />
          <input type="text" name="age" id="newAge"/>
          <input type="button" onclick="addRow();"  value="新增"/>
          </body>
          </html>


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 如东县| 余庆县| 博客| 德安县| 萍乡市| 巴里| 遂溪县| 临汾市| 微山县| 陆河县| 合江县| 油尖旺区| 海盐县| 浦东新区| 新余市| 全椒县| 屏南县| 邢台市| 乌海市| 岳普湖县| 中宁县| 子长县| 博爱县| 东台市| 永昌县| 余庆县| 汶上县| 巧家县| 西平县| 论坛| 益阳市| 青冈县| 文昌市| 五峰| 喀喇沁旗| 陕西省| 宽城| 河间市| 永济市| 岳西县| 会昌县|