我有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>
我的问题是下一步该做什么?我很困惑......
答案 0 :(得分: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
如果您需要更多代码,请告诉我。
答案 1 :(得分: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>