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 badges
Add a ment  | 

6 Answers 6

Reset to default 4

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

本文标签: javascriptjQueryradio button click()Stack Overflow