| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 437 人关注过本帖
标题:不能检测到单选按钮是否被选中
只看楼主 加入收藏
dillon_dai
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-9-28
收藏
 问题点数:0 回复次数:1 
不能检测到单选按钮是否被选中
<script language="javascript">
function yanzheng()
{
if (document.tijiao.user_name.value=="")
{
window.alert("请填写姓名");
document.tijiao.user_name.focus();
return (false);
}
if (document.tijiao.radio.value=="")
{
window.alert("请选择性别");
document.tijiao.radio.focus();
return (false);
}
if (document.tijiao.age.value=="")
{
window.alert("请输入年龄");
document.tijiao.age.focus();
return (false);
}
}
</script>
<form id="form1" name="tijiao" method="post" action="user.asp?da=da1" onsubmit="return yanzheng();">
<label>姓名:
<input type="text" name="user_name" />
</label>
<label><br />
性别: </label>

<label>
<input type="radio" name="xingbie" value="男" />

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

<br />
年龄:
<input name="age" type="text" id="age" />
</label>
<p>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
<label>
<input type="reset" name="Submit2" value="重置" />
</label>
</p>
</form>
搜索更多相关主题的帖子: 按钮 检测 
2007-10-02 22:44
madpbpl
Rank: 4
等 级:贵宾
威 望:11
帖 子:2876
专家分:244
注 册:2007-4-5
收藏
得分:0 

<script language="javascript">
function yanzheng()
{
if (document.tijiao.user_name.value=="")
{
window.alert("请填写姓名");
document.tijiao.user_name.focus();
return (false);
}
var check=true;
for(i=0;i<document.tijiao.xingbie.length;i++){
if(document.tijiao.xingbie[i].checked){
check=false;
break;
}
}
if (check)
{
window.alert("请选择性别");
document.tijiao.xingbie[0].focus();
return (false);
}
if (document.tijiao.age.value=="")
{
window.alert("请输入年龄");
document.tijiao.age.focus();
return (false);
}
}
</script>
<form id="form1" name="tijiao" method="post" action="user.asp?da=da1" onsubmit="return yanzheng();">
<label>姓名:
<input type="text" name="user_name" />
</label>
<label><br />
性别: </label>

<label>
<input type="radio" name="xingbie" value="男" />

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

<br />
年龄:
<input name="age" type="text" id="age" />
</label>
<p>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
<label>
<input type="reset" name="Submit2" value="重置" />
</label>
</p>
</form>
document.表单名.字段名(不是字段类型).value,
这个楼上要注意的

2007-10-02 23:37
快速回复:不能检测到单选按钮是否被选中
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014620 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved