How does jQuery dynamically Add rows with delete buttons?
How does jQuery dynamically Add rows with delete buttons:
In actual use, if you want to operate a table, you can add or delete rows at most. In general, dynamically added rows can also be deleted dynamically, the following is a brief introduction of how to implement this operation. Although it is relatively simple, it is still expected to provide some help to friends who need it.
The code example is as follows:
<! DOCTYPE html>
The code above allows you to dynamically Add rows to a table, and the delete button is at the end of the table row. When you click Delete, you can delete the current row. The implementation process is described below.
I. Implementation principle:
The principle is particularly simple, that is, to declare a string first. This string is the content of the row to be added. When you click the append button, the append () the function appends the string to the end of the table. When you click the delete button, the parent node of the button, that is, the current row, is deleted.
Ii. Related reading:
1. For details about click events, see click events in jQuery.
2. For details about the parent () function, refer to the parent () method section of jQuery.
3. For the remove () function, see the remove () method section of jQuery.
The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 9099.
For more information, see: http://www.softwhy.com/jquery/