How to check a radio button with jQuery?

前端 未结 30 2721
独厮守ぢ
独厮守ぢ 2020-11-22 08:12

I try to check a radio button with jQuery. Here\'s my code:

30条回答
  •  生来不讨喜
    2020-11-22 09:09

    Try this.

    To check Radio button using Value use this.

    $('input[name=type][value=2]').attr('checked', true); 
    

    Or

    $('input[name=type][value=2]').attr('checked', 'checked');
    

    Or

    $('input[name=type][value=2]').prop('checked', 'checked');
    

    To check Radio button using ID use this.

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

    Or

    $('#radio_1').prop('checked','checked');
    

提交回复
热议问题