JavaScript dynamic additive form

xiaoxiao2021-04-04  228

Dynamically add form

Text / ray

Some code is as follows:

One line second Row
third line

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 , inNerText is the text added to , innerhtml is HTML code added to (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.

Newtr.onclick = newclick (); newtr.onclick = 'newclick'

Newtr.onclick = "newclick";

The above writing is wrong.

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.

The following is also correct

Newtr.onclick = function newclick () {

Alert ("This is a new line");

}

This use function name is actually the same.

Set other event usage.

转载请注明原文地址:https://www.9cbs.com/read-131730.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.064, SQL: 9