1

I'm trying to fire a change event for a selected group radio button but this event gets fired if I select an already selected radio button. Can I prevent this from happening?

$("input[type='radio']").mouseup(function(){
    ... 
}).change(function(){
    ...
});

HTML

<label class="radio">
    <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
            Option one
</label>
<label class="radio">
    <input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">
            Option two
</label>
4

1 回答 1

4
$("input[type='radio']:not(:selected)").mouseup(function(){
    ... 
}).change(function(){
    ...
});

OR

$("input[type='radio']:not(:checked)").mouseup(function(){
    ... 
}).change(function(){
    ...
});

:not(:selected) will exclude all selected radios.

Read about :selected and :not() selectors.

于 2012-07-18T18:56:36.990 回答