图像单选按钮在第二次单击时发出意外

我想在第二次点击时取消选择收音机,这非常适用于非图像收音机,但图像收音机出现问题。

查看控制台日志,对于非图像无线电,它将显示 – 检查其中任何一个时为false,未选中时为true

意外或图像收音机 – 按第1个第2个第3个顺序按FB单选按钮,每次当你点击下一个时它应该取消选中前一个,不幸的是在第3个之后再次从第1个第2个重复等。在某些情况下它不会被检查(需要再次按)

我摆弄它却徒劳无功

$(function(){ $('input[type="radio"]').click(function(){ var $radio = $(this); // if this was previously checked if ($radio.data('waschecked') == true) { console.log(true) $radio.prop('checked', false); $radio.data('waschecked', false); } else { $radio.data('waschecked', true); console.log(false) } $radio.siblings('input[name='+ $(this).attr('name') +']').data('waschecked', false); }); }); 
 label > input{ /* HIDE RADIO */ visibility: hidden; /* Makes input not-clickable */ position: absolute; /* Remove input from document flow */ } label > input + img{ /* IMAGE STYLES */ cursor:pointer; border:2px solid transparent; } label > input:checked + img{ /* (RADIO CHECKED) IMAGE STYLES */ border:2px solid #f00; } 
       
press 1 st, 2nd and 3d again 1st (now its unchecked insted of 1st checked)