Jquery dynamically adds a small example of deleting table rows

  • 2020-03-29 23:47:14
  • OfStack

<script src="jquery/jquery-1.3.1.js"></script>
<style type="text/css">
 var show_count = 20;   //Number of bars to display
 var count = $("input:text").val();    //Increment the starting value, and here's your ID
 var fin_count = parseInt(count) + (show_count-1);   //Close the increasing condition
 if(count < fin_count)    //When clicked, if the current number is less than the condition that the increment ends
 $("tr:eq(1)").clone().appendTo("table");   //Add a row after the table
 $("tr:last td input:first").val(++count);   //Change the ID value of the added row.
 function deltr(){
 var length=$("tr").length;
 alert(" Keep at least one line ");
<input type="button" id="btn_addtr" value=" Add line ">
<table id="dynamicTable" width="700" border="0" cellspacing="0" cellpadding="0">
    <td height="30" align="center" bgcolor="#CCCCCC">ID</td>
    <td align="center" bgcolor="#CCCCCC">Username</td>
    <td align="center" bgcolor="#CCCCCC">Usertype</td>
    <td align="center" bgcolor="#CCCCCC">Other</td>
    <td height="30" align="center"><input type="text" size="2" value="1" /></td>
    <td align="center"><input type="text" name="username" /></td>
    <td align="center">
      <select name="type">
    <option value="1">Administrator</option>
    <option value="2">Guest</option>
    <td align="center"><input type="text" name="username2" /></td>
 <td><input type="button" id="btn_deltr" onclick="deltr()" value=" Delete rows "></td>

Related articles: