最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Bootstrap button groups + Radio Buttons, checked value is not working in Firefox using jQuery - Stack Overflow

matteradmin5PV0评论

I'm building a website using bootstrap and using button groups overlaid on top of radio buttons to load certain content based on which radio button is checked . I check value attribute in radio buttons to decide which content to load (using jQuery). Here is JSFiddle for the same.

/

If you run this in Chrome then you get radio button values in alert prompts.

If you run this in Firefox then you get "undefined" in alert prompts.

Any reason, why FF is behaving this way or I have done something wrong.

Thanks in advance!

I'm building a website using bootstrap and using button groups overlaid on top of radio buttons to load certain content based on which radio button is checked . I check value attribute in radio buttons to decide which content to load (using jQuery). Here is JSFiddle for the same.

http://jsfiddle/F2Kr3/1/

If you run this in Chrome then you get radio button values in alert prompts.

If you run this in Firefox then you get "undefined" in alert prompts.

Any reason, why FF is behaving this way or I have done something wrong.

Thanks in advance!

Share Improve this question asked Oct 4, 2012 at 1:20 WizWiz 3071 gold badge6 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

The reason why this works for Chrome is that it triggers the click event down to the input:radio level, while Firefox doesn't have this kind of behavior.

As far as I know, Bootstrap doesn't handle this functionality between buttons and nested input radio buttons. So you'll have to set the checked attribute of the input:radio buttons on click of a Bootstrap styled button.

$('div.btn-group .btn').click(function(){
  $(this).find('input:radio').attr('checked', true);
  alert($('input[name=radio-btn-ctrl]:checked').val());
});

http://jsfiddle/3prAu/1/

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far