無名的博客

          任意增加或刪除一行html元素

          代碼如下:

          <script language="javascript">
          var curRow=null;
          function selectRow(tr1){
          if(curRow)
          curRow.bgColor="#FFFFFF";
          tr1.bgColor="e7e7e7";
          curRow=tr1;
          }
          function addRow(src){
          var newrow = src.insertRow(src.rows.length-1);
          newrow.attachEvent("onclick",function(){selectRow(newrow);});
          newrow.height=20;
          var i=4;
          while(i--){
          var newcell = newrow.insertCell();
          switch(i){
          case 0: newcell.innerHTML= '<input type="button" onClick="javascript:delRow(this.parentElement.parentElement)" value="刪除此行">';break;
          default: newcell.innerHTML=div1.innerHTML;break;
          }
          }
          }
          function delRow(src){
          src.parentElement.deleteRow(src.rowIndex);
          }
          </script>

          <table id="tb" width="100%"  border="1" >
            <tr>
              <th scope="col" width="25%">一</th>
              <th scope="col" width="25%">二</th>
              <th scope="col" width="25%">三</th>
              <th scope="col" width="25%">四</th>
            </tr>
            <tr id="blankRow" onClick="addRow(this.parentElement)">
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
          </table>
          <div id="div1" style="display:none "><inpute type="text"></div>

          posted on 2005-10-18 10:47 十三郎 閱讀(754) 評論(1)  編輯  收藏 所屬分類: JAVASCRIPT

          評論

          # re: 任意增加或刪除一行html元素 2006-08-01 12:31 游俠


          不錯
          很有用  回復  更多評論   

          主站蜘蛛池模板: 砀山县| 阿荣旗| 罗江县| 济南市| 静海县| 宜宾县| 阿拉尔市| 枣庄市| 岳普湖县| 东辽县| 乌兰浩特市| 彰化市| 宜良县| 同心县| 水富县| 潜江市| 绥阳县| 襄城县| 滨州市| 新泰市| 诏安县| 高邑县| 嘉黎县| 利津县| 当雄县| 巴彦县| 金昌市| 涟水县| 大化| 玉环县| 广河县| 弋阳县| 比如县| 鸡泽县| 莱州市| 莒南县| 古田县| 红安县| 龙州县| 始兴县| 江永县|