请问我用js对用户名和密码判空,怎么让它在判断用户名为空的时候回到登陆界面,而不是转到表格提交的页面?
<script>
function sub()
var userName = document.getElementById('userName').value;
if(userName=='') { alert('用户名不能为空'); return false;}else return true;
<script/>
<form method="post" id="form1" name="form1" action='login.action' onsubmit="return sub();"><input type="text" name="userName" id="userName"/></form>
function sub()
var userName = document.getElementById('userName').value;
if(userName=='') { alert('用户名不能为空'); return false;}else return true;
<script/>
<form method="post" id="form1" name="form1" action='login.action' onsubmit="return sub();"><input type="text" name="userName" id="userName"/></form>
温馨提示:答案为网友推荐,仅供参考
第1个回答 2011-04-26
window.location="login.html";
不过你要是判断为空的话,就是应该还在登陆界面啊,
页面应该不需要跳转啊,直接 alert("用户名密码不能为空"); 不就行了~
不过你要是判断为空的话,就是应该还在登陆界面啊,
页面应该不需要跳转啊,直接 alert("用户名密码不能为空"); 不就行了~