开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜