jquery实现radio第一次点击选中第二次点击取消选中的功能

我们都知道radio单选框是不能取消选中的,如果我们想要单选框也实现点击选中再次点击取消选中功能,可以用下面这段jquery代码来实现。

$('input:radio').click(function(){
        if ($(this).data('waschecked') == true){
          $(this).prop('checked', false);
          $(this).data('waschecked', false);
        }else{
          $(this).prop('checked', true);
          $(this).data('waschecked', true);
        }
    });

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: