2009-12-02 168 views
0

我有一個沒有id或名稱的div內的表。我如何讀取jQuery中所需表格單元格的值?例如:從jQuery表中獲取單元格值

<div id="myDiv" style="padding-top: 0px; height: 60px;"> 
<table width="264" cellspacing="0" cellpadding="0" border="0"> 
<tbody> 
<tr> 
    <td width="80" height="20" style="font-size: 10px;"> 
    </td> 
    <td id="the_cell_i_want" align="right" style="color: rgb(102, 188, 41); font-size: 24px;font-weight: bold; background-color: rgb(255, 255, 255); background-image: none;">THE_VALUE_I_WANT</td> 
</tr> 
<tr> 
</tr> 
<tr> 
</tr> 
</tbody> 
</table> 
</div> 

我想要檢索id爲「the_cell_i_want」的單元格,它應該返回「THE_VALUE_I_WANT」。

回答

3
$("#the_cell_i_want").text(); 

會爲你做。

由於您擁有該ID,因此您可以使用id selector唯一地從DOM中選擇元素。您可以使用text獲取單元格值[innerText]。