获取使用jquery选中的复选框的ID

mar*_*ike 2 javascript checkbox jquery

我正在尝试获取类的复选框的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; ?>">
Run Code Online (Sandbox Code Playgroud)

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

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

  });
     });
Run Code Online (Sandbox Code Playgroud)

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

Tus*_*har 5

使用.map

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


如果你想要idchecked的复选框

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


.过滤()