Javascript java脚本表单验证在chrome中运行良好,但在firefox中不起作用?
使用java脚本的表单验证在chrome上运行良好。但不能在firefox中工作 代码:Javascript java脚本表单验证在chrome中运行良好,但在firefox中不起作用?,javascript,forms,Javascript,Forms,使用java脚本的表单验证在chrome上运行良好。但不能在firefox中工作 代码: 函数validateForm() { var x=document.forms[“newuserForm”][“mname”].value; 如果(x==null | | x==“”) { 警告(“必须填写姓名”); 返回false; } var x=document.forms[“newuserForm”][“email”].value; var atpos=x.indexOf(“@”); var do
函数validateForm()
{
var x=document.forms[“newuserForm”][“mname”].value;
如果(x==null | | x==“”)
{
警告(“必须填写姓名”);
返回false;
}
var x=document.forms[“newuserForm”][“email”].value;
var atpos=x.indexOf(“@”);
var dotpos=x.lastIndexOf(“.”);
如果(atpos尝试这段代码,它也可以在firefox中运行
javascript中用于电子邮件验证的验证代码
试试这个var x=document.forms[0].mname.value;'Java'与'JavaScript'的关系就像'Car'与'地毯'的关系一样。“它将注册用户”表示您不必检查客户端发送到服务器的内容。始终检查服务器端。永远不要信任客户端。您也可以共享html代码吗?请注意,返回false;
是不够的。请阅读e.preventDefault();
和e.stopPropagation();
<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>