首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >java脚本表单验证在chrome中运行良好,但在firefox中不起作用?

java脚本表单验证在chrome中运行良好,但在firefox中不起作用?
EN

Stack Overflow用户
提问于 2013-06-17 19:41:17
回答 1查看 297关注 0票数 0

使用java脚本的表单验证在chrome上运行得很好。但不能在firefox中工作。

代码:

代码语言:javascript
运行
复制
<script type="text/javascript">
function validateForm()
{
var x=document.forms["newuserForm"]["mname"].value;
if (x==null || x=="")
  {
  alert("name must be filled");
  return false;
  }

  var x=document.forms["newuserForm"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  {
  alert(" email is not valid");
  return false;
  }



  var x=document.forms["newuserForm"]["password"].value;
if (x==null || x=="")
  {
  alert("password must be filled out ");
  return false;
  }

/*  var x=document.forms["newuserForm"]["age"].value;
if (x==null || x=="")
  {
  alert("Age must be Selected");
  return false;
  }*/
var m = document.getElementById('male');
var f = document.getElementById('female');

if ( (m.checked == false ) && (f.checked == false ) )
{
alert ( "Please select your gender ");
return false;
}
if( document.newuserForm.age.value == "-1" )
   {
     alert( "please select your age group" );
     return false;
   }

if( document.newuserForm.country.value == "-1" )
   {
     alert( "Please select your country");
     return false;
   }

if( document.newuserForm.city.value == "-1" )
   {
     alert( "please select your country" );
     return false;
   }

}
</script>

在chrome中,如果用户没有输入姓名,它会显示一条消息“姓名必须填满”。但是在Firefox中什么也不会显示,如果我点击submit按钮而没有输入名称,它将注册用户。为什么java脚本不能在Firefox上工作?代码有什么问题?

EN

回答 1

Stack Overflow用户

发布于 2013-07-01 22:10:38

试试这段代码,它在firefox中也是有效的

电子邮件验证http://informationiswelth.blogspot.in/的javascript中的验证代码

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17146648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档