JavaScript / HTML尚不成熟,如果这个问题看起来很简单,请抱歉。
基本上,我正在使用JavaScript进行一些测验,并且想知道如何引用所选的“无线电”输入。
function buttonClicked(){
var capitalOption = document.Capital.value; //This line doesn't seem to work.
if(capitalOption == "ottawa"){
console.log("Correct");
}
}
<input type="radio" name="Capital" value = "toronto" class = "formClass"> Toronto <br>
<input type="radio" name="Capital" value = "ottawa" class = "formClass"> Ottawa <br>
<input type="radio" name="Capital" value = "montreal" class = "formClass"> Montreal <br>
<input type="button" id="button" value="Check Answers" class = "formClass" onclick="buttonClicked()">
谢谢!