Recently I have been learning JavaScript. The following is an example (based on the w3cschool example)
In this example, a row is inserted after the row clicked by the mouse. By default, a row is inserted in the first row. You can enter the inserted content by yourself. The Code is as follows:
<Html> <pead> </pead> <body onmousedown = "whichElement (event) "> <table id =" myTable "border =" 1 "> <tr> <td> Row1 cell1 </td> <td> Row1 cell2 </td> </tr> <tr> <td> Row2 cell1 </td> <td> Row2 cell2 </td> </tr> <td> Row3 cell1 </td> <td> row3 cell2 </td> </tr> </table> <p> Cell1: <input type = "text" id = "cell1" value = "cell1"/> Cell2: <input type = "text" id = "cell2" value = "cell2"/> </p> <input type = "button" onclick = "insRow () "value =" insert row "> </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
The content above is inserted to the start position by default.
Note that when you click the insert row button, the action also captures and changes the global variable. At first, I didn't realize that the above red code was not added, therefore, every time you click the insert row, it is inserted in the first line. Originally, according to the original design, When you click the button, the global variable is changed to 0, so it can only be added in the first line.
The simple solution is to add the red code to avoid the problem just now.
The above is only a small learning experience. You can use this as a template, such as deleting a specified row or inserting a row before it.
Continue to learn JavaScript and continue to communicate.