[英]How to know which tables's checkbox is selected?
這是一個功能
function collect_users_and_groups() {
var tos = [];
$('#mytable12 input:checked, #groupsTable1 input:checked').each(function(i, elt) {
//alert("to groups");
var dataids = $(this).parent().attr("data-selected").split(",");
alert("dataids "+dataids);
var name = $.trim($(this).parent().next().text());
tos.push(name);
});
return tos.join(', ');
}
當我選中復選框時會調用它,實際上groupsTable1
具有數據選擇的屬性,而mytable12
沒有。 我想稱其為var dataids = $(this).parent().attr("data-selected").split(",");
單擊groupsTable1復選框時,請告訴我該怎么做?
這是完整的提琴 ,上面的js代碼可以在js部分的22-33之間找到
您可以使用.is()
檢查表是否為groupsTable1。
function collect_users_and_groups() {
var tos = [];
$('#mytable12 input:checked, #groupsTable1 input:checked').each(function(i, elt) {
//Check table is groupsTable1
if($(this).closest('table').is("#groupsTable1")){
//alert("to groups");
var dataids = $(this).parent().attr("data-selected").split(",");
alert("dataids "+dataids);
var name = $.trim($(this).parent().next().text());
tos.push(name);
}
});
return tos.join(', ');
}
只需使用
$('#mytable12 input:checked, #groupsTable1 input:checked').each(function(i, elt) {
代替
$('#groupsTable1 input:checked').each(function(i, elt) {
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.