开发者

How to prevent a second click in a radio button that´s checked?

开发者 https://www.devze.com 2023-03-17 21:31 出处:网络
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.

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.

0

精彩评论

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