admin管理员组

文章数量:1312658

I'm trying to get the id's of the checkboxes with the class file-selection-id. The checkbox is inside a for loop which is why I have placed variables on the id's and names.

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

What I want is that when I click a button, it would get all of the id's of the selected checkboxes.

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

  });
     });

But I don't know how to get the Id's of all the checkboxes that were on the file-selection-id class that I need? What could be ways on how I could call the ID's of the checkboxes(for example if I had 4 checkboxes with 2 selections)?

I'm trying to get the id's of the checkboxes with the class file-selection-id. The checkbox is inside a for loop which is why I have placed variables on the id's and names.

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

What I want is that when I click a button, it would get all of the id's of the selected checkboxes.

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

  });
     });

But I don't know how to get the Id's of all the checkboxes that were on the file-selection-id class that I need? What could be ways on how I could call the ID's of the checkboxes(for example if I had 4 checkboxes with 2 selections)?

Share Improve this question asked Nov 13, 2013 at 3:00 marchemikemarchemike 3,27713 gold badges60 silver badges99 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Use .map

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


if you want id of checked check-boxes

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();


.filter()

本文标签: javascriptGetting id of checkboxes selected using jqueryStack Overflow