【发布时间】:2014-06-14 01:52:25
【问题描述】:
未定义的输出!!我错过了什么吗?有什么想法吗?
这里是单选按钮输入:
<tr>
<td>Yes <input type="radio" name="email" id="email" value="yes"/></td>
<td></td>
<td>No <input type="radio" name="email" id="email" value="no"checked="checked"/></td>
</tr>
<input type="button" value="submit" onclick="doIt()" style="width: 150px; height:30px" />
<script type="text/javascript" language="javascript">
function doIt() {
var emailopt = document.getElementById('email').checked.value;
alert (emailopt);
}
【问题讨论】:
-
var emailopt = document.getElementById('email').checked;你没有关闭<script>标签。此外,您有多个id,它们应该是唯一的。检查这个:stackoverflow.com/questions/1423777/… -
“id”应该是唯一的
-
只注释js函数语句并在里面加上alert,它也不起作用。