判断radio是否被选中

a1337780147 2011-10-24 11:21:21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script>
function check()
{
for(var i=0;i<document.frm.major.length;i++)
{
if(document.frm.major[i].checked!=true)
{
alert('学历还没选择,请选择!');
}
}
}
</script>
<body>
<form name="frm">
<input type="radio" name="major" value="专科" />专科<input type="radio" name="major" value="本科" />本科<input type="radio" name="major" value="硕士研究生" />硕士研究生<br />
<input type="submit" onclick="check()" />
</form>
</body>
</html>

怎么判别不了呢?求解中。。。。。
...全文
65 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
huyoulee 2011-10-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 huyoulee 的回复:]

<script>
function check()
{
var flag = true;
for(var i=0;i<document.frm.major.length;i++)
{
if(document.frm.major[i].checked==true)
{
flag = false;
return;
}
}
if(flag){
aler……
[/Quote]
不好意思alert();后面忘了个return false;
huyoulee 2011-10-24
  • 打赏
  • 举报
回复
<script>
function check()
{
var flag = true;
for(var i=0;i<document.frm.major.length;i++)
{
if(document.frm.major[i].checked==true)
{
flag = false;
return;
}
}
if(flag){
alert('学历还没选择,请选择!');
}
}
</script>
_懒猫 2011-10-24
  • 打赏
  • 举报
回复
jquery
$('[type="radio"]:radio:checked')
MadEric 2011-10-24
  • 打赏
  • 举报
回复
这样第一个不选择就会弹出警告框。

function check()
{
for(var i=0;i<document.frm.major.length;i++)
{
if(document.frm.major[i].checked == true)
{
return;
}
}
alert('学历还没选择,请选择!');
}

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧