簡體   English   中英

如何知道選中了哪個表的復選框?

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM