我在抓取設置爲隱藏的DIV內的表的JQuery中遇到了問題。在隱藏Div中訪問元素數量和值
下面是一個例子:
<div id="questions" style="display: none;">
<table id="tbl_questions">
<thead>
<tr>
<th>Question</th>
<th>Weight</th>
</tr>
</thead>
<tbody>
<tr id="q0">
<td id="td_question0">Some Question 0</td>
<td id="td_wieght0">Some Weight 0</td>
</tr>
<tr id="q1">
<td id="td_question1">Some Question 1</td>
<td id="td_wieght1">Some Weight 1</td>
</tr>
</tbody>
</table>
</div>
注意該表是包含div內。它設置爲顯示:無。當我嘗試運行這個JQuery代碼時,它返回0.
var question_count = $("#tbl_questions> tr").size();
alert(question_count);
任何想法?
我試着找到計數,然後我可以在表中創建每個問題和重量的數組。由於ID爲我提供了一個索引,所以這應該很簡單,但是事實上它就像上面的問題一樣,包含在隱藏的DIV中會成爲一個問題?
感謝, Tegan斯奈德
如果您花時間點擊「接受答案」複選標記,您會發現人們更願意回答您的問題。儘管你已經評論了一些答案已經解決了你的問題,但你僅僅完成了25%的問題。 – Pointy 2010-03-08 20:41:51
你是對的,並且說得很好。 – 2010-03-08 21:25:40