Check a radio button with javascript

前端 未结 6 1670
一个人的身影
一个人的身影 2020-11-27 04:22

For some reason, I can\'t seem to figure this out.

I have some radio buttons in my html which toggles categories:



        
6条回答
  •  一个人的身影
    2020-11-27 04:42

    If you want to set the "1234" button, you need to use its "id":

    document.getElementById("_1234").checked = true;
    

    When you're using the browser API ("getElementById"), you don't use selector syntax; you just pass the actual "id" value you're looking for. You use selector syntax with jQuery or .querySelector() and .querySelectorAll().

提交回复
热议问题