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

前端 未结 2 959
长发绾君心
长发绾君心 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

提交回复
热议问题