![]() |
#2
学飞的小鸟2010-04-12 22:00
|

<%@ page language="java" import="java.util.*" pageEncoding="gb2312" contentType="text/html; charset=gb2312"%>
<html>
<head>
<title>
</title>
<script type="text/javascript">
function checkdata(){
if(form1.username.value==''){
alert("用户名不能为空");
document.getElementById('username').focus();
return false;
}
else if(document.form1.password.value==''||document.form1.swd.value==''){
alert("密码不能为空");
document.getElementById('password').focus();
return false;
}
else if(document.form1.password.value!=document.form1.swd.value)
{
alert("密码不一致");
document.getElementById('password').focus();
return false;
}
else{
response.sendRedirect("LoginCl.jsp");
return true;
}
}
</script>
</head>
<body>
<form name=form1 method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>确认密码: </td>
<td><input type="password" name="swd"></td>
</tr>
<tr>
<td><input type="reset" value="重置"><input type="submit" value="提交申请" onclick=checkdata()></td>
</tr>
</table>
</form>
</body>
</html>
想实现在没有输入用户名的时候提示“用户名为空”,然后光标停在username输入框中<html>
<head>
<title>
</title>
<script type="text/javascript">
function checkdata(){
if(form1.username.value==''){
alert("用户名不能为空");
document.getElementById('username').focus();
return false;
}
else if(document.form1.password.value==''||document.form1.swd.value==''){
alert("密码不能为空");
document.getElementById('password').focus();
return false;
}
else if(document.form1.password.value!=document.form1.swd.value)
{
alert("密码不一致");
document.getElementById('password').focus();
return false;
}
else{
response.sendRedirect("LoginCl.jsp");
return true;
}
}
</script>
</head>
<body>
<form name=form1 method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>确认密码: </td>
<td><input type="password" name="swd"></td>
</tr>
<tr>
<td><input type="reset" value="重置"><input type="submit" value="提交申请" onclick=checkdata()></td>
</tr>
</table>
</form>
</body>
</html>
请问代码有什么问题