[英]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.