How to check a radio button with jQuery?

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

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

30条回答
  •  故里飘歌
    2020-11-22 09:01

    Get value:

    $("[name='type'][checked]").attr("value");
    

    Set value:

    $(this).attr({"checked":true}).prop({"checked":true});
    

    Radio Button click add attr checked:

    $("[name='type']").click(function(){
      $("[name='type']").removeAttr("checked");
      $(this).attr({"checked":true}).prop({"checked":true});
    });
    

提交回复
热议问题