简体   繁体   中英

jQuery - radio button click()

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

You 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
}
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM