Javascript:检查选择了哪个单选按钮

Javascript:检查选择了哪个单选按钮,javascript,Javascript,我查看了论坛,找不到任何对我的问题有直接帮助或与我的问题相关的东西,所以我来看看。我正在为学校制作一个游戏,玩家被分为3个班,每个班旁边都有一个单选按钮。我希望它是,我可以点击一个单选按钮,然后在我做了最后的决定(关于哪个类),我可以点击底部的按钮,然后游戏将继续 <html> <head> <meta charset="utf-8"> <title>Class Select</title> </head>

我查看了论坛,找不到任何对我的问题有直接帮助或与我的问题相关的东西,所以我来看看。我正在为学校制作一个游戏,玩家被分为3个班,每个班旁边都有一个单选按钮。我希望它是,我可以点击一个单选按钮,然后在我做了最后的决定(关于哪个类),我可以点击底部的按钮,然后游戏将继续

<html>

<head>
    <meta charset="utf-8">
    <title>Class Select</title>
</head>
<link rel="icon" type="image/x-icon" href="icon.ico">

<body background="bg2.jpg">

<p align="center"><font size="20" face="verdana" color="white" ><b><u>Select a Class</u></b>    </font></p>
<br><br>

<div align="middle">

<!-- Angel -->
<img src="angel.png" height="110" width="110" alt="The Angel Class">
<input type="radio"  size="20" name="class" class="big" value="Angel" id="class_angel">
<p><font color="aquamarine" size="8"><b>The Angel</b></font></p>
<p><font color="aquamarine" size="6">A born fighter, for all that is good in the world.</font>        </p>
<br>
<p><font color="darkcyan" size="6"><b>Health: 10</b></font></p>
<p><font color="darkcyan" size="6"><b>Damage: 6</b></font></p>
<p><font color="darkcyan" size="6"><b>Starting Item: Halo</b></font></p>
<p><font color="darkcyan" size="4"><b>(Chance of doing double damage when on less than 5 health)

    </b></font></p>
<br><br>

<!-- Beast -->
<img src="beast.png" height="110" width="110" alt="The Beast Class">
<input type="radio"  size="20" name="class" class="big" value="Beast" id="class_beast">
<p><font color="brown" size="8"><b>The Beast</b></font></p>
<p><font color="brown" size="6">Savage at heart, teeth and mind.</font></p>
<br>
<p><font color="burlywood" size="6"><b>Health: 15</b></font></p>
<p><font color="burlywood" size="6"><b>Damage: 4</b></font></p>
<p><font color="burlywood" size="6"><b>Starting Item: Golden Ring</b></font></p>
<p><font color="burlywood" size="4"><b>(Chance of finding more gold)</b></font></p>
<br><br>

<!-- Spirit -->
<img src="spirit.png" height="110" width="110" alt="The Spirit Class">
<input type="radio"  size="20" name="class" class="big" value="Spirit" id="class_spirit">
<p><font color="papayawhip" size="8"><b>The Spirit</b></font></p>
<p><font color="papayawhip" size="6">Easier to see through his lies.</font></p>
<br>
<p><font color="thistle" size="6"><b>Health: 5</b></font></p>
<p><font color="thistle" size="6"><b>Damage: 10</b></font></p>
<p><font color="thistle" size="6"><b>Starting Item: Wandering Soul</b></font></p>
<p><font color="thistle" size="4"><b>(Chance of draining an enemies life)</b></font></p>
<br><br>

<img onclick="continueCheck()" src="next.png" alt="Continue" class="button">

</div>

<style type="text/css" media="screen">
.big{ width: 8em; height: 8em; }
.medium{ width: 16em; height: 8em; }
.button{ width: 6em; height:6em; }
</style>


<!-- Scripting -->
<script type="text/javascript">
function continueCheck()
{
    if(document.getElementById("class_angel") value="Angel")
    {
        console.log("You pressed Angel");
    }else if(document.getElementById("class_beast") value="Beast")
    {
        console.log("You pressed Beast");
    }else if(document.getElementById("class_spirit") value="Spirit")
    {
        console.log("You pressed Spirit");
    }
}
</script>

</body>

</html>

选课

选择一个类



天使

一个天生的斗士,为了世界上的一切美好


健康:10

损坏:6

起始项目:光环

(生命值小于5时造成双倍伤害的几率)



野兽

内心、牙齿和思想都很野蛮


健康:15

损坏:4

起始项目:金戒指

(找到更多黄金的机会)



精神

更容易看穿他的谎言


健康:5

损失:10

开始项目:流浪的灵魂

(消耗敌人生命的机会)



.big{宽度:8em;高度:8em;} .中等{宽度:16em;高度:8em;} .按钮{宽度:6em;高度:6em;} 函数continueCheck() { if(document.getElementById(“class_angel”)value=“angel”) { log(“您按下了Angel”); }else if(document.getElementById(“class_beast”)value=“beast”) { log(“您按下了Beast”); }else if(document.getElementById(“class_spirit”)value=“spirit”) { 日志(“您按下了Spirit”); } }

标签底部的区域似乎不起作用。我收到错误“Uncaught ReferenceError:continueCheck未定义VM68 classSelect.html:52”

您的语法已全部升级:

if(document.getElementById("class_angel") value="Angel")
看看你是如何在行尾有一个随机的“)”的

编辑:我想你可能是想写:

function continueCheck()
{
    if(document.getElementById("class_angel").checked)
    {   
        console.log("You pressed Angel");
    }
    else if(document.getElementById("class_beast").checked)
    {    
        console.log("You pressed Beast");
    }
    else if(document.getElementById("class_spirit").checked)
    {

        console.log("You pressed Spirit");
    }
}

工作完美。谢谢你,阿奎那!