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

如何获得表单焦点
例如:当邮箱错误的提示框出来后,点玩确定又重新跑到此文本框来重新获得焦点
我用的是onblur事件注册的函数,当失去焦点的时候触发checkemail函数,尽管写了document.getElementById("eml").focus();还是不管用,大侠们帮帮我了!希望吃完饭后有个好的解答,谢谢!我会尽快结贴的!

<!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=utf-8" />
<title>登录</title>
<link href="style/style2.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
//检查邮箱
function checkemail(){
var myemail=document.getElementById("eml").value;
var mesg_error= document.getElementById("emai_error");
if(myemail!="")
{//查找@,如果没有就返回-1
if(myemail.indexOf("@")==-1||myemail.indexOf(".")==-1||(myemail.indexOf("@")>myemail.indexOf(".")))
{
//mesg_error.innerHTML="<font color='red'></font>";
alert("email格式不正确!例:xiaoniu@qq.com");
document.getElementById("eml").focus();
return false;
}
else
{
mesg_error.innerHTML="<font color='red'>√</font>";
return true;
}
}
else
{
alert("email不能为空!")
//mesg_error.innerHTML="<font color='red'>email不能为空!</font>";
document.getElementById("eml").focus();
return false;
}


}

//检查密码
function checkpwd()  
{
 var mypwd=document.getElementById("pwd").value;
 var pwd_error=document.getElementById("pwd_error");
 if(mypwd=="")
 {
  //pwd_error.innerHTML="<font color='red'>密码不能为空!</font>";
  alert("密码不能为空");
  return false;
 }
 else if(mypwd.length>=6&&mypwd.length<=16)
 {
  
   pwd_error.innerHTML="<font color='red'>√</font>";
  return true;
 }
 else
 {
 //pwd_error.innerHTML="<font color='red'>密码至少应为6位到16位!</font>";
   alert("密码至少应为6位到16位!");
  return false;
 }
}

//检查确认密码
function checkpwdd()
{
var mypwdd=document.getElementById("pwdd").value;
var pwdd_error=document.getElementById("pwdd_error");

 if(mypwdd=="")
 {
 //pwdd_error.innerHTML="<font color='red'>确认密码不能为空!</font>";
  alert("确认密码不能为空!");
 return false;
 }

else if(document.getElementById("pwdd").value!=document.getElementById("pwd").value)
{
 //pwdd_error.innerHTML="<font color='red'>确认密码与密码不一致!</font>";
  alert("确认密码与密码不一致!");
 return false;

}
else
{
pwdd_error.innerHTML="<font color='red'>√</font>";
return true;

}
}

//检查提交
function regist()
{
 var email_err=document.getElementById('emai_error').innerHTML;
       var pwd_err=document.getElementById('pwd_error').innerHTML;
       var pwdd_err=document.getElementById('pwdd_error').innerHTML;

var yx=document.getElementById("eml").value