问题描述
<scripttype="text/javascript">functionlogin(){if(trim(document.getElementById("username").value)==""){alert("用户名不能为空!");document.getElementById("username").focus();return;}if(trim(document.getElementById("password").value)==""){alert("密码不能为空!");document.getElementById("password").focus();return;}with(document.getElementById("userForm")){method="post";action="user/login.do?command=login";submit();}}</script></head><body><center><h1>登陆</h1><hr><formname="userForm"id="userForm">用户:<inputtype="text"name="username"id="username"><br>密码:<inputtype="password"name="password"id="password"><br><inputname="btnLog"type="button"id="btnLog"value="登陆"onclick="login()"><inputtype="reset"value="取消"><br><ahref=user/registerinput.do>还没用户名,注册一个吧!</a></form><p></center></body>
解决方案
解决方案二:
看起来是没问题的,在仔细检查检查,js有一个错误,就不会提交了,你可以把button改为submit,然后吧onclick的函数换成onsubmit,做个提交检测,试试又没问题
解决方案三:
if(document.getElementById("username").value.trim()==""){alert("用户名不能为空!");document.getElementById("username").focus();return;}if(document.getElementById("password").value.trim()==""){alert("密码不能为空!");document.getElementById("password").focus();return;}
解决方案四:
if(document.getElementById("username").value.trim()==""){alert("用户名不能为空!");document.getElementById("username").focus();return;}if(document.getElementById("password").value.trim()==""){alert("密码不能为空!");document.getElementById("password").focus();return;}
解决方案五:
你的trim函数哪来的?js内置是没有trim函数的需要自己实现,是不是没有包含这个函数啊