Checking Value of Radio Button Group via JavaScript?

前端 未结 8 639
清歌不尽
清歌不尽 2020-12-12 20:36

This may seem silly and downright stupid but I can\'t seem to figure out how to check the value of a radio button group in my HTML form via JavaScript. I have the following

8条回答
  •  离开以前
    2020-12-12 20:49

    Use document.querySelector() if you want to avoid frameworks (which I almost always want to do).

    document.querySelector('input[name="gender"]:checked').value
    

提交回复
热议问题