日期:2014-05-16  浏览次数:20390 次

麻烦下大家,我觉得要疯了,,看了一下午都没看出为什么无法正确输出结果。。。

我怎么都没有看出来,为什么不能正确地输出性别的情况呢!!!麻烦大家看看!!
function hs()
{
//全局判断
var judge=true;

//输出的文字
var str="";

//姓名的判断
var name=document.getElementById("name").value;
if(name.length==0)
{
document.getElementById("namenull").innerHTML="姓名不能为空";
judge=false;
}
else
{
document.getElementById("namenull").innerHTML="";
str+="姓名:"+name;
}

//密码判断
var password=document.getElementById("password").value;
if(password.length==0)
{
document.getElementById("passwordnull").innerHTML="密码不能为空";
judge=false;
}
else
{
document.getElementById("passwordnull").innerHTML="";
str+="\n密码:"+name;
}

//性别判断
var sex=document.myform1.sex;
var s="";
var check=false;
  for(var i=0;i<=sex.length;i++)
  {
  if(document.myform1.sex[i].checked)
  {
  s+=document.myform1.sex[i].value;
  check=true;
  }
  }
if(!check)
{
document.getElementById("sexnull").innerHTML="性别要选择";
    judge=false;
}
else
{
document.getElementById("sexnull").innerHTML="";
 str+="\n性别:"+s;
}
/*if(s.length==0)
  {
  document.getElementById("sexnull").innerHTML="性别要选择";
  judge=false;
  }
 else
 {
 document.getElementsById("sexnull").innerHTML="";
 str+="\n性别:"+s;
 }*/
  
  



if(judge)
{alert (str);}
}









</script>
<form name="myform" id="myform1" >
<fieldset>
<legend>调查表</legend>
<div align="center">调查表</div>
姓名&nbsp;<input type="text" id="name" />                                                            <label id="namenull" ></label><br /><br />

密码&nbsp;<input type="password" id="password" />                                                    <label id="passwordnull"></label><br /><br />

性别&nbsp;<input type="radio" name="sex" value="男"/>男 
           <input type="radio" name="sex" value="女"/>女                                              <label id="sexnull"></label><br /><br />