我需要執行以下操作:檢查tr的第3個td是否包含(完全)56,然後檢索包含在第一個td中的複選框的ID行。jquery檢索某些元素的ID並將它們寫入數組
<table>
<tr class="bg">
<td nowrap="nowrap">
<input class="selected_ads" type="checkbox" id="43617" />
</td>
<td class="pa">text text</td>
<td class="pa">56</td>
</tr>
<tr class="bgwhite">
<td nowrap="nowrap">
<input class="selected_ads" type="checkbox" id="183578" />
</td>
<td class="pa">text</td>
<td class="pa">56</td>
</tr>
</table>
($(。」 BG TD:第n個孩子(3):含有('56' ) 「)長度> 0)或($(」 TD bgwhite:第n個孩子(3) :contains('56')「)。length> 0)檢查第三個單元格是否包含我正在查找的值。 (「。pa」)。siblings()。first()。children(「input [type ='checkbox']」) 讓我複選框,但我無法檢索其ID。
理想的情況下我的代碼是這樣的:
var longlist = [];
for each ($(".bg td:nth-child(3):contains('56')").length>0) {
retrieve the id of $(".pa").siblings().first().children("input[type='checkbox']");
longlist.push(checkbox_id);
}
爲.bgwhite這樣做;
理想情況下它也可以工作。
對我來說最重要的是檢索id。
很有可能您在每次迭代中選擇第一個值。你有沒有使用'.each'方法? – 2013-02-25 16:08:27