Today, someone in the group suddenly asked me $ ("#MainContent_GridView1"). Closest ("tr"). Children ("Td:eq (1)"). Text () This statement does not find a value. I asked him to take a tr below eq (1) of TD's text or all. He said all the .... Then sure to cycle all of the TR, and then from which to find TD ...
Here I write a simple blog to help friends who still don't know how to use the jquery selector.
I simulate a table out, to give you a reference, the following is the HTML structure
Copy Code code as follows:
<table id= "Maincontent_gridview1" >
<tbody>
<tr >
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr >
<td>11</td>
<td>22</td>
<td>33</td>
</tr>
;tr>
<td>111</td>
<td>222</td>
<td>333</td>
</tr> Br></tbody>
</table>
//I introduced a local jquery file that was not introduced in the article. The
<script type= "Text/javascript" >
$ (function () {
///First finds the table ID as Maincontent_gridview1, and then Find tbody below all the TR then each loop, $ (this) on behalf of the current loop to the Tr,children is the TD under TR then select the subscript is 1 again text () came out.
$ ("#MainContent_GridView1 tbody tr"). each (function (i) {
Alert ($ (this). Children ("Td:eq (1)"). text ());
});
})
</script>