Use jquery to dynamically add a row to the specified table and delete one row of methods _jquery

Source: Internet
Author: User
Tags first row

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

Today in the project, just used to add a row to the specified table, delete a row, directly to find Google, search out the things are not satisfactory, not function is not the same, is simply a waste of time is not flattering, and then do their own packaging, now the code to share out, to avoid the repetition of the wheel to build, If there is a problem welcome everyone to make a brick, do not be personal attack, quack ...

Requirements Scenario

1), add a row

Supports adding one row to any row and configurable, such as adding a row to the first row, adding a row to the second row, adding a row to the penultimate row, and adding a row to the penultimate row, without affecting the change in demand.

Prerequisite: The number of rows must exist in the table or the addition is unsuccessful.

2), delete a row

Supports dynamic deletion of a row.

First show the results, if you like to study the code well.

1, the original interface is as follows:



2, add a line, if you want to add a line to click the "Add" button, now click Two will automatically add two lines, the effect of the following screenshot:



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



4, the selected row to delete, now click the "Delete" button will be selected to delete the row, the effect of the following screenshot:



The code is as follows:

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

The above is a small set for everyone to use jquery to add a row to the specified table dynamically, delete a row of methods all the content, I hope that we support cloud-Habitat Community ~

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.