我有一張表,每行都有一個複選框。如何獲取表中的選定行?
此代碼適用於另一個表:
jQuery('#my_table_id tr').has(':checkbox:checked').closest('tr').each(function() {
request_arr[i] = jQuery(this).attr('id');
i++;
});
現在,在這種情況下,我有一個表對象:
var tbl = $('#my_table') // In my code, this is done dynamically
// This does not work
jQuery(tbl + 'tr').has(':checkbox:checked').closest('tr').each(function() {
request_arr[i] = jQuery(this).attr('id');
i++;
});
我怎樣才能獲得使用像tbl
表對象檢查行? 我嘗試了各種深入,但我無法得到任何工作。
更新
這是我如何設置我的html:
<table id="t1"></table>
<div class="bulk_action">
<div title="Remove requests" class="trash_iconset_grey_16px removeRequest"></div>
<div title="some other button" class="abc"></div>
</div>
<table id="t2"></table>
<div class="bulk_action">
<div title="Remove requests" class="trash_iconset_grey_16px removeRequest"></div>
<div title="some other button" class="abc"></div>
</div>
點擊下面表1中的 「按鈕」,將設置tbl = <table id="t1">
。
@elcanrs解決方案也將在表2 NR取檢查行我只想爲表NR 1
right - 'jQuery('tr',tbl)'將工作 - 使用tbl作爲選擇的上下文。 – StilgarBF 2012-03-15 21:22:13
@elcanrs我試過之前,它的工作原理......但問題是,我有我的第一張桌子下面的另一張桌子。如果我也檢查該表中的某些複選框,那麼這將包含在我的'find - each'中。我只需要在'tbl'中查找選中的行。 – Steven 2012-03-15 21:27:38
@Steven:然後你的結構出了問題。 'find'只會找到所選元素的後代。 – 2012-03-15 21:30:35