Based on jquery implementation Click on the last line to achieve the row of the table _jquery

Source: Internet
Author: User

Now any transaction is the pursuit of efficiency and humanization, of course, the page effect is also so, if a table can be edited data, edit to the last line, click can automatically add a row, this is a more humane effect, you can dispense with a trace of fatigue suffering, the following share a piece of such code.

The code is as follows:

<! DOCTYPE html>  

The above code to achieve our requirements, click on the last line of the table, you can automatically add a new line, the following describes its implementation process.

A. Code comments:

1.$ (function () {}) to execute code in the function when the document structure is completely loaded.
2.var otable = $ ("#count"), gets the object with the id attribute value of Count, which is the Table object.
3.iNum = 1, declare a variable and assign an initial value of 1, which can be +1 as the line number for each additional row.
4.eEle = ', declaring a variable to store the Row object.
5.otable.on (' click ', Function (e) {}) to register the click event handler for a Table object.
6.var target = E.target, gets the source object being clicked.
7.oTr = $ (target). Closest (' tr ') to get the most recent TR ancestor element.
8.F (Otr.index () ==otable.find (' tr '). Last (). index ()) to determine whether the clicked is the final line.
The 9.inum++,inum value plus 1.
10.eEle = Otr.clone () to clone the current row object.
11.eele.find (' TD '). EQ (0). Text (Inum) to set the value of the first cell in the last row.
12.otable.append (Eele) to add a row to the end of the table.

About jquery Implementation Click on the last line of the table to achieve the effect of all the contents of the form to introduce so many, the above content to a great comment, there is not understand where to refer to, thank you all the time to the cloud-Habitat community website support.

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.