登陆判定的js,比较实用。也是本猫第一个写在代码里上交的js例子
<script type="text/javascript">
//读取用户输入信息
function login() {
var userName = document.getElementById("username").value; //获取用户名
var password = document.getElementById("password").value; //获取密码
//当用户名和密码都非空时自动登录
if(userName == "")
{
form1.username.focus();
document.getElementById("div_name").innerHTML="您未输入用户名!";
return false;
}
if(password == "")
{
form1.password.focus();
document.getElementById("div_pass").innerHTML="您未输入密码!";
return false;
}
}
function checkName(str)
{
if(str==""){
document.getElementById("div_name").innerHTML="请输入用户名!";
}else{
document.getElementById("div_name").innerHTML="";
}
}
function checkPass(str)
{
if(str==""){
document.getElementById("div_pass").innerHTML="请输入密码!";
}else{
document.getElementById("div_pass").innerHTML="";
}
}
</script>
<form method="post" id="form1" action="UserLoginServlet" οnsubmit="return login()">
<TABLE class=weight259 border=0 cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD align=right>姓名:</TD>
<TD><INPUT style="COLOR: #000" id=username class=input140 onBlur="checkName(this.value)"
name=username>
</TD>
</TR>
<tr><td> </td><td><SPAN id="div_name"class=text_red></SPAN></td></tr>
<TR>
<TD align=right>密码:</TD>
<TD><INPUT style="COLOR: #000" id=password class=input140 type=password onBlur="checkPass(this.value)"
name=password></TD></TR>
<TR>
<TD> </TD><td><SPAN id="div_pass"class=text_red></SPAN></td>
</TR>
<TR>
<td></td>
<TD colspan="2" align=left><input type="image" name="ImageButton1" id="ImageButton1"
src="image/btn_logon1.gif">
<a href="zhuce.jsp"><img src="image/btn_login.gif" alt="注册" ></a>
</TD></TR>
<TR>
</TR>
</TBODY>
</TABLE>
</FORM>
<script type="text/javascript">
//读取用户输入信息
function login() {
var userName = document.getElementById("username").value; //获取用户名
var password = document.getElementById("password").value; //获取密码
//当用户名和密码都非空时自动登录
if(userName == "")
{
form1.username.focus();
document.getElementById("div_name").innerHTML="您未输入用户名!";
return false;
}
if(password == "")
{
form1.password.focus();
document.getElementById("div_pass").innerHTML="您未输入密码!";
return false;
}
}
function checkName(str)
{
if(str==""){
document.getElementById("div_name").innerHTML="请输入用户名!";
}else{
document.getElementById("div_name").innerHTML="";
}
}
function checkPass(str)
{
if(str==""){
document.getElementById("div_pass").innerHTML="请输入密码!";
}else{
document.getElementById("div_pass").innerHTML="";
}
}
</script>
<form method="post" id="form1" action="UserLoginServlet" οnsubmit="return login()">
<TABLE class=weight259 border=0 cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD align=right>姓名:</TD>
<TD><INPUT style="COLOR: #000" id=username class=input140 onBlur="checkName(this.value)"
name=username>
</TD>
</TR>
<tr><td> </td><td><SPAN id="div_name"class=text_red></SPAN></td></tr>
<TR>
<TD align=right>密码:</TD>
<TD><INPUT style="COLOR: #000" id=password class=input140 type=password onBlur="checkPass(this.value)"
name=password></TD></TR>
<TR>
<TD> </TD><td><SPAN id="div_pass"class=text_red></SPAN></td>
</TR>
<TR>
<td></td>
<TD colspan="2" align=left><input type="image" name="ImageButton1" id="ImageButton1"
src="image/btn_logon1.gif">
<a href="zhuce.jsp"><img src="image/btn_login.gif" alt="注册" ></a>
</TD></TR>
<TR>
</TR>
</TBODY>
</TABLE>
</FORM>