jquery mutually get value of exclusive checkbox
Hi I need a sample code to get the value of selected checkbox. The checkboxes are mutually exclusive and I开发者_StackOverflow would like to get the selected checkbox value on the click of a button Thanks
selected checkbox??
maybe you want checked checkbox....
html
<input type="checkbox" name="Checkbox1">
<input type="checkbox" name="Checkbox2" checked="checked">
<input type="checkbox" name="Checkbox3">
<input type="button" name="button1" value="see checked">
jQuery
$(function(){
$('input:button').click(function(){
alert($('input:checkbox:checked').attr('name'));
})
})
if multiple are checked
$(function(){
$('input:button').click(function(){
$('input:checkbox:checked').each(function(){
alert($(this).attr('name'));
});
})
})
demo
精彩评论