我已将此选择所有脚本用于选择复选框。
$(document.body).on('click', '#selecctall', function () {
if (this.checked) { // Check select status
$('.chkAssets').each(function () { // Loop through each checkbox
this.checked = true; // Select all checkboxes with class "chkAssets"
$(this).attr('value', this.checked ? 1 : '')
});
} else {
$('.chkAssets').each(function () { // Loop through each checkbox
this.checked = false; // Deselect all checkboxes with class "chkAssets"
$(this).attr('value', this.checked ? '' : '')
});
}
});
现在我想选中复选框id
,以逗号分隔,其值为1
。
注意:我想获得按钮点击事件的结果。
我的 JSFiddle 工作:http://jsfiddle.net/ybtreuhg/
最佳答案
尝试
$("#getAll").click(function () {
var id = $("[type=checkbox][value=1]:checked").map(function () {
return this.id;
}).get().join(",");
alert(id);
});
<强> DEMO
关于javascript - 如何获取以逗号分隔的选定复选框 ID,其值为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25678936/