admin管理员组

文章数量:1315297

Requirement : I want to 'disable Click of a radio button' using JQuery. The radio button will be already checked, before click.

Conditions:

1) The disable attribute should not be set to true. Means we must not radio button to make click disable on it.

2) If user clicks on that radio button, then it should not get unchecked.

Why Such Requirement: A Common JQuery is already written for onClick of all Radios in form. I want it not to get executed at all for particular radio.

As I do not have authority to change that jQuery. That JQuery enable disable some other elements on form on clicking of radio.

so i need to handle that in my Jquery either onload or some other method. I hope requirements are clear. Please help!!

Update: From Answers i have created three fiddle but none worked yet.

1) / 
2) /
3) /

Looking, If someone can contribute more

Requirement : I want to 'disable Click of a radio button' using JQuery. The radio button will be already checked, before click.

Conditions:

1) The disable attribute should not be set to true. Means we must not radio button to make click disable on it.

2) If user clicks on that radio button, then it should not get unchecked.

Why Such Requirement: A Common JQuery is already written for onClick of all Radios in form. I want it not to get executed at all for particular radio.

As I do not have authority to change that jQuery. That JQuery enable disable some other elements on form on clicking of radio.

so i need to handle that in my Jquery either onload or some other method. I hope requirements are clear. Please help!!

Update: From Answers i have created three fiddle but none worked yet.

1) https://jsfiddle/uhxpmexe/ 
2) https://jsfiddle/ry5zqcv7/
3) https://jsfiddle/k0gd57ks/

Looking, If someone can contribute more

Share Improve this question edited May 13, 2015 at 8:05 fatherazrael asked May 13, 2015 at 7:36 fatherazraelfatherazrael 5,98719 gold badges87 silver badges190 bronze badges 2
  • 4 Do you mean that you do not want people to be able to change the value in the radio buttons, but also do not want them to be disabled? – Rory McCrossan Commented May 13, 2015 at 7:37
  • Right. Do not want to Disable the Radio and do not want user to click it. If clicked and also do not want the mon jquery to get executed at all (which gets executed on click). – fatherazrael Commented May 13, 2015 at 7:45
Add a ment  | 

5 Answers 5

Reset to default 3

You can simply return false in click handler:

 $(":radio").click( function(){
         return false;
 });

Working Demo

Update: As you have already defined click handler, you need to unbind it and then add new click handler which returns false:

$("#ba").unbind('click').click( function(){
     return false;
 });

Working Demo

I think you are asking "How can I remove an event handler from a specific radio button after some other code (which I don't have access to) adds the handler to all radio buttons in my form?"

If this is correct, you could simply give your radio an id and then call: $( "#myRadio").unbind( "click" );

Just use event.preventDefault() jsfiddle

pointer-events: none; should do the trick. With addClass in jQuery you can add it any time

.disabled{
    cursor: not-allowed; /* aesthetics */
    pointer-events: none;
}

Also check out: https://css-tricks./almanac/properties/p/pointer-events/

you can use this code for disabled the radio button.

$(".example").attr('disabled','disabled');

Please let me know if code working for you.

本文标签: javascriptHow to Disable Click on a radio button without disabling it in JQueryStack Overflow