zoukankan      html  css  js  c++  java
  • js动态添加和删除行

    1. <html>  
    2.   
    3. <head>  
    4. <title>js-sample</title>  
    5.   
    6. <script type="text/javascript">  
    7. <!--  
    8. var count = 1;  
    9. function add() {  
    10.   var tbl = document.all.ci;  
    11.   var rows = tbl.rows.length;  
    12.   var tr = tbl.insertRow(rows);  
    13.      
    14.   var name = tr.insertCell(0);  
    15.   name.innerHTML = '<input type="text">';  
    16.   var tel = tr.insertCell(1);  
    17.   tel.innerHTML = '<input type="text">';  
    18.   var rdo = tr.insertCell(2);  
    19.   rdo.innerHTML = '<input type="radio" value="0" name="rdo' + count + '">Yes <input type="radio" value="1" name="rdo' + count + '">No';  
    20.   var chk = tr.insertCell(3);  
    21.   chk.innerHTML = '<input type="checkbox" value="0" name="chk' + count + '">Modify <input type="checkbox" value="1" name="chk' + count + '">Delete';  
    22.   var del = tr.insertCell(4);  
    23.   del.innerHTML = '<input type="button" onclick="del(this)" value="Delete">';  
    24.   count++;  
    25. }  
    26.   
    27. function del(btn) {  
    28.   var tr = btn.parentElement.parentElement;  
    29.   var tbl = tr.parentElement;  
    30.   tbl.deleteRow(tr.rowIndex-1);  
    31. }  
    32. //-->  
    33. </script>  
    34. </head>  
    35.   
    36. <body>  
    37.   
    38. <input type="button" onclick="add()" value="Add-Customer">  
    39.   
    40. <table border="1" style="100%" id="ci" name="ci">  
    41.   <caption>customer information</caption>  
    42.   <thead>  
    43.   <tr>  
    44.   <th>Name</th>  
    45.   <th>Tel</th>  
    46.   <th>Radio</th>  
    47.   <th>CheckBox</th>  
    48.   <th</th>  
    49.   </tr>  
    50.   </thead>  
    51.   <tbody>  
    52.   <tr>  
    53.   <td><input type="text" value="Zhang San"></td>  
    54.   <td><input type="text" value="111"></td>  
    55.   <td>  
    56.   <input type="radio" value="0" name="rdo">Yes <input type="radio" value="1" name="rdo">No  
    57.   </td>  
    58.   <td>  
    59.   <input type="checkbox" value="0" name="chk">Modify <input type="checkbox" value="1" name="chk">Delete  
    60.   </td>  
    61.   <td>  
    62.   <input type="button" onclick="del(this)" value="Delete">  
    63.   </td>  
    64.   </tr>  
    65.   </tbody>  
    66. </table>  
    67.   
    68. </body></html>  
  • 相关阅读:
    移动前端工作的那些事---前端制作之动画效率问题简析
    PHP从零开始-笔记-面向对象编程的概念
    php从零开始
    jquery表单验证
    Jquery网页加载进度条(随笔,当然要随便写,当日记动态心情写咯)
    Jquery实现花瓣随机飘落(收藏自慕课网)
    seajs的那点事(很坑的事),和本白的一点事(更坑的事)
    js高级群的一些整理6月
    有关jquery checkbox获取checked的问题
    最近忙着考试又是什么的,然后群里都在秀战绩,秀一下那些年的战绩吧
  • 原文地址:https://www.cnblogs.com/shenqz/p/6961047.html
Copyright © 2011-2022 走看看