简体   繁体   English

如何使用jQuery从两个表选中的复选框中获取值?

[英]how to get from two table checked checkbox values using jquery?

Here I have two tables, and in each table I have checked boxes. 这里有两个表,每个表中都有一个复选框。 I am getting the checked values from both, but I am saving in two different arrays and combining to into a single one. 我从这两个中都获取了检查值,但是我将其保存在两个不同的数组中并组合成一个数组。

Is there any way to get the checked checkbox values from both tables, but only from these tables? 有什么方法可以从两个表中(但仅从这些表中)获取选中的复选框值吗?

My Attempt: 我的尝试:

 var First = [];
 var Second = [];
 First = $("#table1 input:checkbox:checked").map(function () {
     First[i] = $(this).val();
     return $(this).val();
 }).get();
 Second = $("#table2 input:checkbox:checked").map(function () {
     Second[i] = $(this).val();
     return $(this).val();
 }).get();

 var subjes = First + Second;

Just use a selector that selects checkboxes in both tables before you map them : 在映射它们之前,只需使用选择器即可选择两个表中的复选框:

var boxes  = $('input:checkbox:checked', '#MainContent_CBLFYSubjects, #MainContent_CBLSYSubjects'),
    subjes = $.map(boxes, function(el){
        return el.value;
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM