开发者

jquery mutually get value of exclusive checkbox

开发者 https://www.devze.com 2022-12-30 12:55 出处:网络
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

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

精彩评论

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