How to set radio button status with JavaScript

前端 未结 8 1273
抹茶落季
抹茶落季 2020-12-04 21:11

What method would be best to use to selectively set a single or multiple radio button(s) to a desired setting with JavaScript?

8条回答
  •  萌比男神i
    2020-12-04 21:34

    Vanilla Javascript:

    yourRadioButton.checked = true;
    

    jQuery:

    $('input[name=foo]').prop('checked', true);
    

    or

    $("input:checkbox").val() == "true"
    

提交回复
热议问题