日期:2014-05-17  浏览次数:20699 次

firefox下 判断用户名为空的问题
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<!--上面的不能删除或修改,因涉及到样式-->
<HTML>
<HEAD><TITLE>登录</TITLE>
<META content="text/html; charset=utf-8" http-equiv="Content-Type">
<META content="no-cache, must-revalidate" http-equiv="Cache-Control">
<META content="0" http-equiv="expires">
<!--
function check(){
          if(document.getElementById("usrname").value.length<3 || document.getElementById("usrname").value.length==""||document.getElementById("usrname").value=="请输入用户名") {
          alert(document.getElementById("usrname").value);
        loginForm.Login.focus();
        return false;
    }

}
//-->
</SCRIPT>
<BODY >
<FORM  name="loginForm" action="check.jsp" method="post" onsubmit='return check()'>
<INPUT onblur="if(this.value=='') this.value='请输入用户名';this.className='inputstyle';return true;" 
  id="usrname" class="inputstyle" onfocus="if(this.value=='请输入用户名') this.value='';this.className='inputstylefocus';return true;"  value="请输入用户名" maxLength="20" style="line-height:26px"  name="Login" autocomplete="off">
 <INPUT class="loginbtn" onMouseDown="this.className='loginbtnfocus';return true;" value="提交" type="submit" name="login"> 
</FORM>
</BODY >
</HTML>


在其他浏览器下正常,在firefox会提交到check.jsp页面

------解决方案--------------------
正常提交都會post 在check.jsp
------解决方案--------------------
这个前边加上<script>就行了

<!--
function check(){
------解决方案--------------------
探讨
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<!--上面的不能删除或修改,因涉及到样式-->
<HTML>
<HEAD><TITLE>登录</TITLE>
<META content="text/html; charset=utf-8" http-equiv="Content-Type">
<……

------解决方案--------------------
问题出在这句话:“loginForm.Login.focus();”

因为你在Login的onfocus事件中,最后return true;

把它注释掉吧。FireFox的JS是比较奇怪的。