JavaScript traverses a column in a row in the table and prints its value. javascripttable

Source: Internet
Author: User

JavaScript traverses a column in a row in the table and prints its value. javascripttable

JavaScript traversal table

1. Description

Traverse a column of a row in the table and print its value

2. Source Code

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

3. Implementation result

(1) During Initialization

(2) Click "traverse"

(3) Click "traverse" again"


How to get the td value of a column in a table, javascript jQuery, all rows, as long as they can be implemented

<BODY>
<Table>
<Tr> <td> 11 </td> <td> 12 </td> <td> 13 </td> </tr>
<Tr> <td> 21 </td> <td> 22 </td> <td> 23 </td> </tr>
<Tr> <td> 31 </td> <td> 32 </td> <td> 33 </td> </tr>
</Table>
</BODY>

<Script>

// Tr: eq (0) take the first row td: eq (2) take the third column
// $ ("Tr: eq (0) td: eq (2)"). text () Get: 13
// $ ("Tr: eq (1) td: eq (1)"). text () Get: 22
Alert ($ ("tr: eq (0) td: eq (2)"). text ());
</Script>

You can replace rows and columns with variables!
Please adopt it. Thank you!

How does jquery obtain the value of a column in a table?

Make sure that the JQeruy file is referenced. If yes, check whether an error is returned.
Put the following code into the body tag.
-----------------------------------------------------
<Form id = "formLoad" runat = "server">
<Table>
<Tr>
<Td> 11 </td>
<Td> 12 </td>
</Tr>
<Tr>
<Td> 21 </td>
<Td> 22 </td>
</Tr>
<Tr>
<Td> abc </td>
<Td> 32 </td>
</Tr>
<Tr>
<Td> 41 </td>
<Td> 42 </td>
</Tr>
</Table>
</Form>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("Tr td: first-child"). each (function (){
If ($ (this). text () = "abc "){
Alert ("yes ");
}
});
});
</Script>

Related Article

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.