Use jquery to add a row to a specified table dynamically and delete a row

Source: Internet
Author: User

$ ("#mytable tr"). Find ("Td:nth-child (1)") 1 means get the first column of each row
$ ("#mytable tr"). Find ("Td:nth-child (3)") 3 means get the third column of each row

Today in the project, just use to add a row to the specified table, delete a row, directly to Google, the search out of things is not satisfactory, not the function is not good is the same, it is a waste of time not to please, and so on their own hands encapsulated, and now the code to share out, to avoid repeating the wheel, If you have any questions, please do not make any personal attacks, quack ...

Demand Scenarios

1), add a row

Support to add a row and configurable on any row, such as can add a row in the first row, add a row in the second row, the first line to add a row, the penultimate row to add a row, with the change in demand will not affect.

Prerequisites: The number of rows needs to exist in the table or the add is unsuccessful.

2), delete a row

Supports dynamic deletion of a row.

Show the results first, as you would like to study the code well.

1. The original interface is as follows:

2, add a row, if you want to add a line to click the "Add" button, now click Two will automatically add two lines, the effect is as follows:

3, delete a row, if you want to delete the specified line, first select the row and then click on the "Delete" button to delete (this is not nonsense ~ ~ ~ ~), now select a row, the effect is as follows:

4, delete the selected row, now click the "delete" button will delete the selected row, the effect is as follows:

The code is as follows:

<%@ page language= "java" pageencoding= "UTF-8"%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

  

Use jquery to add a row to a specified table dynamically and delete a row

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.