Tracking deselecting radio
Is there a way to track when a radio element gets deselected?
<script type="text/javascript">
$().ready(function() {
$('#answer-1').change(function(){
console.log('radio-1 changed');
});
$('#answer-2').change(function(){
console.log('radio-2 changed');
});
});
</script>
<input name="question-1" type="radio" id="answer-1" />Value
<input name="question-1" type="radio" id="answer-2" />Value
J开发者_如何学GoSFiddle link
Expected result: When selecting answer-1, it shows event 'radio-1 changed', then when switching to answer-2, it should show radio-2 changed AND radio-1 changed
Actual result: When selecting answer-1, it shows event 'radio-1 changed', then when switching to answer-2, it shows only 'radio-2 changed'
Is there a way to get events when the radio's get DEselected?
you can use .data
here is the fiddle that may help http://jsfiddle.net/wZ73z/19/
Try this
<script type="text/javascript">
$().ready(function() {
$('input[name=question-1]').change(function(){
if(this.checked)
console.log('radio is selected');
else
console.log('radio is note selected');
});
});
</script>
精彩评论