1
如何从未知数量的复选框创建一个数组,使用jquery向数组中添加值?然后发布数组?将未知数量的选中复选框的值添加到数组
如何从未知数量的复选框创建一个数组,使用jquery向数组中添加值?然后发布数组?将未知数量的选中复选框的值添加到数组
var arr = $.map($('input[type="checkbox"]:checked'),function(checkbox){
return checkbox.value;
})
你可以试试这个:
function updateTextArea() {
var allVals = [];
$('#c_b :checked').each(function() {
allVals.push($(this).val());
});
$('#t').val(allVals)
}
$(function() {
$('#c_b input').click(updateTextArea);
updateTextArea();
});