Using jquery, how do i check a radio button based on a variable value?

前端 未结 2 950
长发绾君心
长发绾君心 2021-02-19 10:14

I have a list of radio buttons. I need to make one of them checked based on the variable i have. How do i accomplish this? The problem is i have no control of what the radio but

相关标签:
2条回答
  • 2021-02-19 10:48

    you can use the attribute equals selector to target the correct radio then use .prop() to set the checked property

    $('input[name=CAT_Custom_378508][value=' + preSelect + ']').prop('checked',true)
    

    FIDDLE

    0 讨论(0)
  • 2021-02-19 11:09

    Try this:

    $('input[type=radio][value=' + preSelect + ']').attr('checked', true);
    
    0 讨论(0)
提交回复
热议问题