Use JavaScript to obtain the specified rows and columns in the table.

Source: Internet
Author: User

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 ~

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.