Home >Web Front-end >JS Tutorial >Use javascript to delete the current line and add a line (sample code)_javascript skills

Use javascript to delete the current line and add a line (sample code)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:12:401020browse

删除行

复制代码 代码如下:

<script>   <br>  function   del(obj)   <br>  {   <br>        obj.parentNode.parentNode.removeNode(true);   <br>  }     <br>  </script>  
    
    
 
     
     
    
  
      
     
  
   
      
     
  
 
单元格1
单元格2
单元格3
  
 

添加行
复制代码 代码如下:

<script><br><br> function uf_test(){<br>  //得到table对象<br>   var tbTable = document.getElementById("tb_test");<br>   //插入一行<br>   var trT = tbTable.insertRow();<br><br>   //得到上一行的td数<br>   var nRows = tbTable.rows[0].cells.length;<br><br>   //按上一行的td数循环进行插入td<br>   for(var i = 0; i < nRows ; i ){<br>    //创建td对象<br>    var tdT = document.createElement("TD");<br>    //给td对象赋值<br>    //tdT.innerHTML="sfsdf";  <br>    tdT.innerText="sfsdf"; <br>    //把td添加到tr中 <br>    trT.appendChild(tdT);<br>   }<br> }<br><br></script>


 
 
 


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn