繁体   English   中英

获取使用jQuery选择的复选框的ID

[英]Getting id of checkboxes selected using jquery

我正在尝试使用class file-selection-id获取复选框file-selection-id 该复选框位于for循环内,这就是为什么我将变量放在ID和名称上的原因。

<input class="file-selection-id" type="checkbox" value="" name="file<?php echo $i; ?>_<?php echo $t; ?>" id="file<?php echo $i; ?>_<?php echo $t; ?>">

我想要的是,当我单击一个按钮时,它将获得所选复选框的所有ID。

$('.move-file-buttons').click( 
function(event) { 
  //??? 
$('input:checkbox.file-selection-id').each(function () {

  });
     });

但是我不知道如何获取我需要的文件选择ID类中所有复选框的ID? 有什么方法可以调用复选框的ID(例如,如果我有4个带有2个选择的复选框)?

使用.map

var arr = $('input:checkbox.file-selection-id').map(function () {
    return this.id;
}).get();


如果您想要checked复选框的id

var arr = $('input:checkbox.file-selection-id').filter(':checked').map(function () {
    return this.id;
}).get();

var arr = $('input:checkbox.file-selection-id:checked').map(function () {
    return this.id;
}).get();


。过滤()

暂无
暂无

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

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