我正在尝试使用class获取复选框的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();
id
的 checked
的复选框
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();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句