The JavaScript function of the dynamically added table line is as follows:
Function addrow () {// Add a line var newtr = testtbl.inSertrow (); // Add two column var newTD0 = newtr.insertcell (); var newtd1 = newtr.insertcell (); // Set the column content and attribute newtd0. Innerhtml = ''; newtd2.innerText = 'new plus';}
Just as simple, do a detailed description:
1, INSERROW () and INSERTCETCETCETCELL () functions
The insertrow () function can be used with parameters, as follows:
INSERTROW (INDEX)
This function adds a new line to the line of Index, such as INSERTROW (0), is before adding new rows to the first line. The default InsertRow () function is equivalent to INSERTROW (-1), and the new row is added to the table.
INSERTCETRELL () and INSERTROW are the same.
2, dynamic setting properties and events
InnerHTML and Innertext in the above lines are column properties.
This inner is "Inner" to tb>, inNerText is the text added to tb>, innerhtml is HTML code added to tb> (This SO is simple, this explanation is quite extra)
Setting other properties It is also the same way, for example, set the row background color.
NEWTR.BGCOLOR = 'Red';
The same is true for setting events.
For example, I want to make a defined function newclick when you click on a new step, and the number of NEWCLICK lines is as follows:
Function newclick () {
Alert ("This is a new line");
}
The code for setting this function for the onclick event is as follows:
Newtr.onclick = newclick;
What is needed here is that = behind the part must be a function name, and it is not a quotation mark.
Why, in fact, know why it doesn't mean, know how to use it, if you don't want to know, you can skip the following paragraph.
In fact, this = New NewClick is a pointer to the NewClick function you defined. The function name in JavaScript is a pointer to the function, and the browser that quotes parentheses can not find that function.