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
5 Answers
Reset to default 3You 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
版权声明:本文标题:javascript - How to Disable Click on a radio button without disabling it in JQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741978902a2408282.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论