jQuery check/uncheck radio button onclick

前端 未结 24 2769
滥情空心
滥情空心 2020-12-01 05:23

I have this code to check/uncheck a radio button onclick.

I know it is not good for the UI, but I need this.

$(\'#radioinstant\').click(function() {          


        
24条回答
  •  时光说笑
    2020-12-01 05:44

    here is simple solution i hope it will help you. here's a simple example to improve answer.

    $('[type="radio"]').click(function () {
    
                if ($(this).attr('checked')) {
    
                    $(this).removeAttr('checked');
                    $(this).prop('checked',false);
    
                } else {
    
                    $(this).attr('checked', 'checked');
    
                }
            });
    

    Demo sorry for too late.. :)

提交回复
热议问题