admin管理员组文章数量:1291599
Is it possible to disable standard action being performed while clicking radio button? (without "disable" attr)
So when i click particular radio button, nothing happens. Tried .unbind('click') but doesnt seem to work.
Ty in advance for help
Is it possible to disable standard action being performed while clicking radio button? (without "disable" attr)
So when i click particular radio button, nothing happens. Tried .unbind('click') but doesnt seem to work.
Ty in advance for help
Share asked Feb 9, 2012 at 15:02 Maciej JaśniaczykMaciej Jaśniaczyk 6057 silver badges17 bronze badges6 Answers
Reset to default 4You can use the preventDefault() method exposed by the event
object:
$("input:radio").click(function(e) {
e.preventDefault();
});
EDIT: Unfortunately, this does not seem to prevent the browser from checking the radio button that is clicked first (jsFiddle is in "emergency read-only" mode, so I cannot post a demo right now).
This should work:
$('#myradio').click(function(e) {
e.preventDefault();
return false;
});
Just try this.
$('input:radio').click(function(e){
e.preventDefault();
});
Demo
You can try this, this will stop propagation :
$("#my-radio-btn").live("click", function(e){
e.preventDefault();
});
Actually, the first time you click the radio, the checked property is set and hence it shows as checked in browser ( for the firtst time ).
So this piece of code will solve the issue
[I am using jquery library]
$('input:radio').click(function(){
$(this).prop('checked',false);
e.preventDefault();
return false;
});
You need to use event.disableDefault in the function you give to jQuery click.
$("#my_element").click(
function(event) {
event.preventDefault();
// the rest of your code goes here
}
);
本文标签: javascriptjQueryradio button click()Stack Overflow
版权声明:本文标题:javascript - jQuery - radio button click() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741534339a2383942.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论