我正在使用此代码来获取当前选定单选按钮的值,但它不起作用.
I am using this code to get the value of currently selected radio button, but it doesn't work.
var mailcopy = document.getElementById('mailCopy').value;
如何使用 Javascript 获取当前选中的单选按钮值?
How to get the currently selected radio button value using Javascript?
HTML
<p>Gender</p>
<input type="radio" id="gender0" name="gender" value="Male">Male<br>
<input type="radio" id="gender1" name="gender" value="Female">Female<br>
JS
var gender = document.querySelector('input[name = "gender"]:checked').value;
document.writeln("You entered " + gender + " for your gender<br>");
这篇关于如何使用js获取选定的单选按钮值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!