-9

我有 3 个单选按钮:红色、蓝色和绿色 当我选择三个单选按钮之一时,应该会出现一个弹出框(警报),并且应该显示所选单选按钮的文本(例如:蓝色)。谁能提供它的javascript代码。谢谢你

对此感到抱歉,这是我对 javascript 代码的尝试:

function radioEvent (radio) 
{
var dom = document.getElementById("myForm");
  for (var index = 0; index < dom.radioButton.length;index++) 
  {
    if (dom.radioButton[index].checked) 
    {
      radio = dom.radioButton[index].value;
    }
  }
}


<td rowspan = "2" >
<input type="radio" name= "radioButton" value= "radio1"> Excellent<br>
<input type="radio" name="radioButton"  value="radio2" > Very Good <br>
<input type="radio" name="radioButton"  value="radio3" > Good <br>
<input type="radio" name="radioButton"  value="radio4" > Satisfactory
        </td>

我的问题是下一步该怎么做?我很困惑...

4

2 回答 2

1

我只是在编写 HTML 代码:

<input id="a1" type="radio" name="group1" value="Red" onclick="alert('Red');">red <br>
<input id="a2" type="radio" name="group1" value="Blue" onclick="alert('Blue');" > Blue<br>
<input id="a3" type="radio" name="group1" value="Green" onclick="alert('Green');"> green

如果您需要更多代码,请告诉我。

于 2012-10-11T02:39:15.417 回答
0
<script type="text/javascript">
function radioEvent(form) 
{
 for (var i = 0; i < form.radioButton.length; i++) 
 {
    if (form.radioButton[i].checked)
    {
        alert("You chose " + form.radioButton[i].value + ".")
    }
 }
 }
</script>
</head>
<body>
<form>
<input type="radio" name= "radioButton" value= "Excellent"   onclick="radioEvent(this.form);"/> Excellent<br/>
<input type="radio" name="radioButton"  value="Very Good" onclick="radioEvent(this.form);"/> Very Good <br/>
<input type="radio" name="radioButton"  value="Good" onclick="radioEvent(this.form);"/> Good <br/>
<input type="radio" name="radioButton"  value="Satisfactory" onclick="radioEvent(this.form);"/> Satisfactory
</form>
</body>
</html>
于 2012-10-12T17:15:11.330 回答