2014-02-28 57 views

回答

1

使用本

$IDs = $("#table input:checkbox:checked").map(function() { 
    return $(this).attr("id"); 
}).get(); 
+0

我做了一個編輯,簡化了代碼 –

0

有一些問題與您的選擇:

1)使用find()或:

$("#table input[type=checkbox]") // or $('#table').find('input[type=checkbox]') 

讓你的表

2)內選中的複選框使用:checked選擇,以獲得複選複選框

$('#table').find('input[type=checkbox]:checked') 

3)您可以使用map()得到選中的複選框的ID的數組:

var checkedArr = $("#table").find("input[type=checkbox]:checked").map(function() { 
    return this.id; 
}).get(); 
1

嘗試:

var checkedBoxes = $("input[type=checkbox]:checked", "#table"); 
2

使用:checked jQuery中。檢索所有數值意味着在jQuery中使用的每個jQuery中

var selected = new Array(); 
$('#table input[type="checkbox"]:checked').each(function() { 
    selected.push($(this).attr('id')); 
}); 
console.log(selected); 

或地圖()

$("#table input[type=checkbox]:checked").map(function() { 
    return this.id; 
}).get(); 
0
$('input[type="checkbox"]:checked').each(function() { 
    // use 'this' to return the value from this specific checkbox 
    console.log($(this).val()); 
}); 

注意$('input[name="myRadio"]').val()不返回檢查無線電輸入的價值,正如你所期望的那樣 - 它會回收甕中組的價值第一個單選按鈕。

See also this question.

相關問題