How to clear radio button in Javascript?

后端 未结 10 597
予麋鹿
予麋鹿 2020-12-02 19:57

I have a radio button named \"Choose\" with the options yes and no. If I select any one of the options and click the button labeled \"clear\", I need to clear the selected o

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 20:23

    You don't need to have unique id for the elements, you can access them by their name attribute:

    If you're using name="Choose", then:

    • With jQuery it is as simple as:

      $('input[name=Choose]').attr('checked',false);
      
    • or in pure JavaScript:

         var ele = document.getElementsByName("Choose");
         for(var i=0;i
      
      

      Demo for JavaScript

提交回复
热议问题