欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          javascript如何刪除一行

          在javascript中,可以使用remove函數(shù)刪除一行,語法格式為“元素對象.remove()”。remove()方法移除被選元素,包括所有文本和子節(jié)點。

          javascript如何刪除一行

          本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。

          javascript在form表單中增加數(shù)據(jù)到表格中,也可以單獨刪除某一行

          remove() 方法移除被選元素,包括所有文本和子節(jié)點。

          該方法不會把匹配的元素從 jQuery 對象中刪除,因而可以在將來再使用這些匹配的元素。

          但除了這個元素本身得以保留之外,remove() 不會保留元素的 jQuery 數(shù)據(jù)。其他的比如綁定的事件、附加的數(shù)據(jù)等都會被移除。這一點與 detach() 不同。

          javascript如何刪除一行

          <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>Title</title>     <style>         #container {             text-align: center;         }          #mytable {             width: 500px;             text-align: center;             border: 1px solid #ccc;             margin: 0 auto;         }          #mytable td, #mytable th {             border: 1px solid #ccc;         }          #myfrm {             line-height: 30px;         }     </style>     <script>         window.onload = function () {             $("btnAdd").onclick = function(){                 //創(chuàng)建tr                 let tr = document.createElement('tr');                 //創(chuàng)建td                 let tdName = document.createElement('td');                 let tdAge = document.createElement('td');                 let tdSex = document.createElement('td');                 let tdPhone = document.createElement('td');                 let tdDelete = document.createElement('td');                  //td中放數(shù)據(jù)                 tdName.innerText = $('name').value;                 tdAge.innerText = $('age').value;                 tdSex.innerText = $('m').checked?$('m').value:$('f').value;                  tdPhone.innerText = $('phone').value;                  //這邊如果不添加刪除,增加數(shù)據(jù)之后,會刪除不了                 let btndelete = document.createElement('input');                 btndelete.type='button';                 btndelete.value='刪除';                 btndelete.onclick = function(){                     this.parentNode.parentNode.remove();                 }                 tdDelete.appendChild(btndelete);                  //td放入tr;                 tr.appendChild(tdName);                 tr.appendChild(tdAge);                 tr.appendChild(tdSex);                 tr.appendChild(tdPhone);                 tr.appendChild(tdDelete);                  //tr放入表格                  $('tb').appendChild(tr);             }               //刪除             let btnlist = document.querySelectorAll('.delete');             for(let i = 0;i<btnlist.length;i++){                 btnlist[i].onclick = function () {                     this.parentNode.parentNode.remove();                 }             }           }          function $(id) {             return document.getElementById(id);         }     </script> </head> <body> <p id="container">     <table id="mytable">         <thead>         <tr>             <th>姓名</th>             <th>年齡</th>             <th>性別</th>             <th>電話</th>             <th>操作</th>         </tr>         </thead>         <tbody id="tb">         <tr>             <td>tom</td>             <td>20</td>             <td>male</td>             <td>110</td>             <td>                 <input type="button" value="刪除" class="delete">             </td>         </tr>         <tr>             <td>jack</td>             <td>22</td>             <td>male</td>             <td>119</td>             <td><input type="button" value="刪除" class="delete"></td>         </tr>         <tr>             <td>alice</td>             <td>25</td>             <td>female</td>             <td>120</td>             <td><input type="button" value="刪除" class="delete"></td>         </tr>         </tbody>     </table>     <hr>      <form action="" id="myfrm">         姓名:<input type="text" id="name"> <br>         年齡:<input type="text" id="age"> <br>         性別:<input type="radio" name="sex" id="m" value="male" checked> 男         <input type="radio" name="sex" id="f" value="female"> 女 <br>         電話:<input type="text" id="phone"> <br>         <input type="button" value="添    加" id="btnAdd">         <input type="reset" value="重    置">     </form> </p>  </body> </html>

          【推薦學(xué)習(xí):javascript高級教程】

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號