jQuery check/uncheck radio button onclick

前端 未结 24 2662
滥情空心
滥情空心 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:47

    This function will add a check/unchecked to all radiobuttons

    jQuery(document).ready(function(){
    jQuery(':radio').click(function()
    {
    if ((jQuery(this).attr('checked') == 'checked') && (jQuery(this).attr('class') == 'checked'))
    {   
        jQuery(this).attr('class','unchecked');
        jQuery(this).removeAttr('checked');
    } else {
    jQuery(this).attr('class','checked');
    }//or any element you want
    
    });
    });
    

提交回复
热议问题