如何从JavaScript引用选择的选项

时间:2019-06-16 20:08:59

标签: javascript html input

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()">

谢谢!

0 个答案:

没有答案