jquery dynamic Add cut table row special effects _jquery

Source: Internet
Author: User

Adding the deletion code based on the jquery table is a dynamic increase in the deletion table row effect code. Share to everyone for your reference. Specifically as follows:
The screenshot of the running effect is as follows:

The specific code is as follows:

HTML code:

<div style= "width:720px;margin:20px auto;" > <table id= "tab11" style= "Display:none" > <tbody> <tr> <td height= "Al" ign= "center" > <input type= "text" name= "NO" size= "2" value= "1"/> </td> <td align= "center" > <input type= "text" name= "Start_end_time"/> </td> <td Align = "center" > <input type= "text" name= "unit_department"/> </td> <td align= "ce  Nter "> <input type=" text "name=" post "/> </td> <td> <input Type= "button" id= "Button1" onclick= "deltr (This)" value= "delete line"/> </td> </tr> </tbody > </table> <input type= "button" id= "BTN_ADDTR" value= "Add lines"/> <table id= "dynamictable" width= "70 0 "border=" 0 "cellspacing=" 0 "cellpadding=" 0 "> <thead> <tr> <TD height= "align=" "Center" bgcolor= "#CCCCCC" >ID</td> <td align= "center" bgcolor= "#CCCCCC" > Start/Start time & lt;/td> <td align= "center" bgcolor= "#CCCCCC" > Unit/Department </td> &LT;TD align= "center bgcolor=" #C CCCCC "> Position </td> <td></td> </tr> </thead> <tbody> &L t;tr> <td height= "align=" center "> <input type=" text "name=" NO "size=" 2 "value=" 1 "/&gt
         ; </td> <td align= "center" > <input type= "text" name= "Start_end_time"/> </ td> <td align= "center" > <input type= "text" name= "unit_department"/> &LT;/TD&G
         T
           &LT;TD align= "center" > <input type= "text" name= "post"/> </td> <td> 
<input type= "button" id= "Button2" onclick= "deltr (This)" value= "delete line"/> </td> </tr>     </tbody> </table> </div>
 

JS Code:

$ (function () {
      var show_count =;  The number of bars to display
      var count = 1;  Increment start value, here is your ID
      $ ("#btn_addtr"). Click (function () {
 
        var length = $ ("#dynamicTable tbody tr"). Length;
        alert (length);
        if (length < Show_count)  //Click Time, if the current number is less than the increment end condition
        {
          $ ("#tab11 tbody tr"). Clone (). Appendto ("# DynamicTable tbody ");  Add a row after the table
          Changeindex ();//Update line number
        }
      }
    ); function Changeindex () {
      var i = 1;
      $ ("#dynamicTable tbody tr"). each (function () {//Cyclic tab TBODY TR
        $ (this). Find ("Input[name= ' NO ')"). Val (i++); Update line number
      });
 
    function deltr (OPP) {
      var length = $ ("#dynamicTable tbody tr"). Length;
      alert (length);
      if (length <= 1) {
        alert ("Keep at least one row");
      } else {
        $ (OPP). Parent (). Parent () remove ();//removing Current line
        Changeindex ();
      }
    

Hopefully this article will help you learn about JavaScript as a programming program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.