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:
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.