1. Increase the line
For example, set table ID to tab var trhtml = "<tr><td>...</td></tr>"
$ ("#tab"). Append (trhtml);//Add a row to the last face of the table
$ ("#tab Tr:eq (2)"). After (trhtml); Add a row after the 3rd row of the table
This can be dynamically added to the line, as to what you are the event to dynamically add that depends on your own meaning, through the button or div and other click events to add, just put the above two lines of code in the OK, note, to put the Var trhtml that line of code into the Add event, Otherwise, no matter how many clicks, you can add only one row
$ (function () {
$ (": Button"). Click (function () {
var tr = "<tr><td>new</td></tr>";
$ ("table"). Append (tr);
$ ("Table Tr:eq (2)"). After (TR);
});
});
This is the code that I tested with, you can run to see
2. jquery deletes the specified row in table
The number of rows is click the Delete button to pass through the master to help answer
1 |
$ (' Table Tr:eq (1) '). Remove (); |
Ask:
My number of rows is the click button to pass the past should write
Chase Answer:
How do you pass the code?
Ask:
<input type= "button" value= "x" onclick= "DELETETR (1)"/>
Chase Answer:
function Deletetr (i) {
$ (' Table Tr:eq (' + i + ') '). Remove ();
Ask:
No , I didn't respond when I clicked the Delete button.
Chase Answer:
Yes, you can see what's wrong.
Ask:
I changed to $ (' #table tr:eq (' + i + ') '). Remove (), but Delete is always not the number of rows I passed the output of I would not be 0 if not 1 What's going on?
Chase Answer:
Do you have a lot of buttons, like when I delete the second line, the third line becomes the second line?
Ask:
I have a lot of buttons on a page. But I only have one button in my table. Answer:
<input type= "button" value= "x" onclick= "Deletetr (This)"/>
function deletetr (obj) {
$ (obj). Parent (' TR ') ). Remove ();
Ask:
Oh, yes
Chase Answer:
Try the above.
Ask:
No, no, click the Delete button.
Chase Answer:
function Deletetr (obj) {
$ (obj). Closest (' tr '). Remove ();
Questioner evaluation
Thank you!
3. Get table row and column Count
function init ()
{
var table =document.getelementbyid ("Tab1");
var rows = table.rows.length;
Alert (' Number of rows ' +rows);
var colums = table.rows[0].cells.length;
Alert (' Number of columns ' +colums);
}