Home > Web Front-end > JS Tutorial > js form login verification example

js form login verification example

高洛峰
Release: 2016-12-09 16:08:27
Original
1089 people have browsed it

The example in this article describes the js form login verification method. Share it with everyone for your reference, the details are as follows:

<!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==&#39;&#39;)
  {
   $(&#39;s1&#39;).innerHTML=&#39;姓名不能为空&#39;;
   $(&#39;s1&#39;).style.color=&#39;red&#39;;
   return false;
  }
  else
  {
    $(&#39;s1&#39;).innerText=&#39;ok&#39;;
    $(&#39;s1&#39;).style.color=&#39;green&#39;;
    return true;
  }
}
//验证密码
function checkpwd(){
  var password=$("password").value;
  if(password==&#39;&#39;)
  {
   $(&#39;s2&#39;).innerHTML=&#39;密码不能为空&#39;;
   $(&#39;s2&#39;).style.color=&#39;red&#39;;
   return false;
  }
  else
  {
    $(&#39;s2&#39;).innerHTML=&#39;ok&#39;;
    $(&#39;s2&#39;).style.color=&#39;green&#39;;
    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=&#39;s1&#39;></span>
    <input name="password" type="password" value="" class="pw" id="password" onblur="checkpwd();"/><span id=&#39;s2&#39;></span>
    </div>
  </div>
  <div class="lg_foot">
  <input type="submit" value="Login In" class="bn" /></div>
</form>
</div>
</body>
</html>
Copy after login


Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template