How to check a radio button with jQuery?

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

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

30条回答
  •  情书的邮戳
    2020-11-22 09:07

    For versions of jQuery equal or above (>=) 1.6, use:

    $("#radio_1").prop("checked", true);
    

    For versions prior to (<) 1.6, use:

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

    Tip: You may also want to call click() or change() on the radio button afterwards. See comments for more info.

提交回复
热议问题