您的当前位置:首页js表单登陆验证示例

js表单登陆验证示例

2020-11-27 来源:乌哈旅游

本文实例讲述了js表单登陆验证的方法。分享给大家供大家参考,具体如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>项目后台管理系统</title>
<link rel="stylesheet" href="__PUBLIC__/css/login.css" />
<script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
<script type="text/javascript">
function $(id)
{
 return document.getElementById(id);
}
//验证姓名
function checkname(){
 var name=$("admin_name").value;
 if(name=='')
 {
 $('s1').innerHTML='姓名不能为空';
 $('s1').style.color='red';
 return false;
 }
 else
 {
 $('s1').innerText='ok';
 $('s1').style.color='green';
 return true;
 }
}
//验证密码
function checkpwd(){
 var password=$("password").value;
 if(password=='')
 {
 $('s2').innerHTML='密码不能为空';
 $('s2').style.color='red';
 return false;
 }
 else
 {
 $('s2').innerHTML='ok';
 $('s2').style.color='green';
 return true;
 }
}
//验证所有表单提交
function checkall()
{
 if(checkname()&&checkpwd())
 {
 return true;
 }
 else
 {
 return false;
 }
}
</script>
</head>
<body class="b">
<div class="lg">
<form action="__URL__/dologin" method="POST" onsubmit="return checkall();">
 <div class="lg_top"></div>
 <div class="lg_main">
 <div class="lg_m_1">
 <input name="admin_name" value="" class="ur" id="admin_name" onblur="checkname();"/><span id='s1'></span>
 <input name="password" type="password" value="" class="pw" id="password" onblur="checkpwd();"/><span id='s2'></span>
 </div>
 </div>
 <div class="lg_foot">
 <input type="submit" value="Login In" class="bn" /></div>
</form>
</div>
</body>
</html>
显示全文