Preface:
I would like to thank George wing for his generous book "Understanding JavaScript", which makes me feel the importance of technical exchanges ~
Go to the topic. One of the questions is:How can I use JavaScript to obtain the values of specified rows and columns in a table?Because Javascript is so easy to test and its usage is flexible, it has to be prevented. The best way is to master them!
Method Analysis:
First, deploy the environment: Use HTML to construct a 3*3 table. A server control textbox is used to receive the obtained Table value and a button to trigger the event of getting the value. For details, seeCode:
Code < Head Runat = "Server" >
< Title > Demonstrate getting table values </ Title >
< Script Type = "Text/JavaScript" Language = "JavaScript" >
// Description: javascript is used to obtain the element values of specified rows and columns in a table.
// Copyright: http://www.cnblogs.com/yangmingming
// Notes: a simple table is used and obtained using textbox.
Function Gettable23 ()
{
VaR Txt = Document. getelementbyid ( " Txtreceiver " );
// First, use the ID-marked TD element to obtain the value.
TXT. Value = Document. getelementbyid ( " 23 " ). Innerhtml;
// Type 2: Use the get table (through its ID) to specify the row and column to be obtained
VaR Valuetd = Document. getelementbyid ( " TBL " ). Rows [ 1 ]. Cells [ 2 ];
TXT. Value = Valuetd. innerhtml;
}
</ Script >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< Div >
< Table Style = "Width: 100% ;" ID = "TBL" >
< Tr >
< TD >
11
</ TD >
< TD >
12
</ TD >
< TD >
13
</ TD >
</ Tr >
< Tr >
< TD >
21
</ TD >
< TD >
22
</ TD >
< TD ID = "23" >
23
</ TD >
</ Tr >
< Tr >
< TD >
31
</ TD >
< TD >
32
</ TD >
< TD >
33
</ TD >
</ Tr >
</ Table >
< ASP: textbox ID = "Txtreceiver" Runat = "Server" > </ ASP: textbox >
< Input ID = "Btnsubmit" Type = "Button" Value = "Get" Onclick = "Gettable23 ()" ; />
</ Div >
</ Form >
</ Body >
</ Html >
The debugging result is:
We can see that the values of the second and third columns are obtained as scheduled.
In summary, it is necessary and urgent to continuously learn JavaScript. With the help of existing materials and networks, we strive to achieve a deep understanding and application of these materials as soon as possible. Haha ~