jQuery set radio button

前端 未结 12 2036
执笔经年
执笔经年 2020-12-02 11:12

I am trying to set a radio button. I want set it by using the value or the id.

This is what I\'ve tried.

$(\'input:radio[name=cols]\'+\" #\"+newcol).         


        
12条回答
  •  情书的邮戳
    2020-12-02 11:24

    In your selector you seem to be attempting to fetch some nested element of your radio button with a given id. If you want to check a radio button, you should select this radio button in the selector and not something else:

    $('input:radio[name="cols"]').attr('checked', 'checked');
    

    This assumes that you have the following radio button in your markup:

    
    

    If your radio button had an id:

    
    

    you could directly use an id selector:

    $('#myradio').attr('checked', 'checked');
    

提交回复
热议问题