js:
var obj = document.getElementsByName("yk"); var check_val = []; for(k in obj){ if(obj[k].checked) check_val.push(obj[k].value); }
jquery:
$(document).ready(function(){ var checked = []; $("#submitButton").click(function(){ $(‘input:checkbox:checked‘).each(function() { checked.push($(this).val()); }); alert(checked); }); });
$(document).ready(
function
(){
var
checked = [];
$(
"#submitButton"
).click(
function
(){
$(
‘input:checkbox:checked‘
).each(
function
() {
checked.push($(
this
).val());
});
alert(checked);
});
});
时间: 2024-10-07 02:54:18