[英]How to know which tables's checkbox is selected?
This is a function 这是一个功能
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(', ');
}
which is called when I select check boxes Actually groupsTable1
has data-selected attribute but mytable12
does not have. 当我选中复选框时会调用它,实际上
groupsTable1
具有数据选择的属性,而mytable12
没有。 I want to call this var dataids = $(this).parent().attr("data-selected").split(",");
我想称其为
var dataids = $(this).parent().attr("data-selected").split(",");
when checkbox of groupsTable1 is clicked Please tell me how to do? 单击groupsTable1复选框时,请告诉我该怎么做?
This is the full fiddle ,the above js codes can be found in between 22-33 in the js section 这是完整的提琴 ,上面的js代码可以在js部分的22-33之间找到
You can use .is()
to check table is groupsTable1. 您可以使用
.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(', ');
}
Simply use 只需使用
$('#mytable12 input:checked, #groupsTable1 input:checked').each(function(i, elt) {
instead of 代替
$('#groupsTable1 input:checked').each(function(i, elt) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.