How to prevent a second click on a radio button that´s already checked?
The ideia i开发者_JAVA百科s to deny the possibility of clicking again in the same radio button.
Regards, RG
You could prevent the event if it has been clicked before:
var clicked = false;
$('input:radio.yourclass').click(function(event){
if (clicked){
event.preventDefault();
}
clicked = true;
});
You could also disable it, but then it's value is not posted to the server - if you need control over more buttons, it can be done, please provide your markup
Example here = http://jsfiddle.net/LUkw9/1/
Add something like this to the function that is executed when the radio-button is clicked
jQuery("#parentElement input:radio").attr('disabled',true);
Instead of
input:radio
you might also target a specific id for a radio button.
<input type="radio" name="example1" id="example1">
<input type="radio" name="example2" id="example2">
With this
('#example2').click(function(){
alert("handling radiobutton, complete!");
jQuery("#example1").attr('disabled',false);
jQuery("#example2").attr('disabled',true);});
This is a bit quick (but not nececerly dirty) of course, and you should loop trough them if the form has an unknown number of radio-buttons.
精彩评论