How to reset radiobuttons in jQuery so that none is checked

后端 未结 13 795
一个人的身影
一个人的身影 2020-11-29 16:35

I have radio buttons in HTML like this:


    1
    

        
13条回答
  •  Happy的楠姐
    2020-11-29 17:15

    I know this is old and that this is a little off topic, but supposing you wanted to uncheck only specific radio buttons in a collection:

    $("#go").click(function(){
        $("input[name='correctAnswer']").each(function(){
          if($(this).val() !== "1"){
            $(this).prop("checked",false);
          }
        });
      });
    
    1
    2
    3
    4
    

    And if you are dealing with a radiobutton list, you can use the :checked selector to get just the one you want.

    $("#go").click(function(){
      $("input[name='correctAnswer']:checked").prop("checked",false);
    });
    
    
    1
    2
    3
    4
    
    

提交回复
热议问题