asp如何判断单选被选中

来源:百度知道 编辑:UC知道 时间:2024/07/02 00:23:28
<td width="160"><input type="radio" name="xingbie" value="男" />

<input type="radio" name="xingbie" value="女" />
女</td>

if (document.form1.xingbie.value=="") {
alert("对不起!性别不能为空!");
return false;
}

这样写得不到验证啊,我知道这样肯定是有问题,怎么改啊?

用 getElementById()函数来得到
给它们一个ID
var e=getElementById("xingbie");
if(e.value=="")
{
alert("对不起!性别不能为空");
return false;
}

if (!document.form1.xingbie.checked) {
alert("对不起!性别不能为空!");
return false;
}