Home > Web Front-end > JS Tutorial > body text

Detailed example of js implementation of login and registration interface

小云云
Release: 2018-05-18 14:25:44
Original
8574 people have browsed it

This article mainly introduces the js implementation of the login and registration interface in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

Complete the HTML+CSS+JS of the login and registration page. The input items checked include:

Username 6-12 digits

The first letter cannot be a number

Can only contain letters and numbers

Password 6-12 digits

Whether the two passwords on the registration page are consistent

html code:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>欢迎你,请先登陆!</title>
 <script type="text/javascript" src="../static/jsp/lx.js"></script>
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
 <link rel="stylesheet" href="../static/css/lx.css">

</head>
<body>
<p class="box">
 <h2>登陆</h2>

 <p class="input_box">
  <input id="uname" type="text" name="user" placeholder="请输入用户名">
 </p>
 <p class="input_box">
  <input id="upass" type="password" name="psw" placeholder="请输入密码">
 </p>
 <p id="error_box"><br></p>
 <p class="input_box">
  <button type="button" class="btn btn-primary" onclick="fnLogin()">登陆</button>&nbsp&nbsp&nbsp&nbsp
  <a href="regist.html"><input type="button" class="btn btn-info" name="regist" value="注册"></a>
 </p>



</p>
</body>
</html>
Copy after login

css code:

*{
 margin: 0;
 padding: 0;
 font-family: 微软雅黑;
 font-size: 12px;
}
.box{
 width: 390px;
 height: 320px;
 border: solid 1px #ddd;
 background: #FFF;
 position: absolute;
 left: 50%;
 top:42%;
 margin-left: -195px;
 margin-top: -160px;
 text-align: center;
}
.box h2{
 font-weight: normal;
 color:#666;
 font-size: 16px;
 line-height: 40px;
 overflow: hidden;
 text-align: center;
 border-bottom: solid 1px #ddd;
 background: #f7f7f7;
}
.input_box{
 width:350px;
 padding-bottom: 15px;
 margin: 0 auto;
 overflow: hidden;
}
Copy after login

javascript code:

function fnLogin() {
 var oUname = document.getElementById("uname")
 var oUpass = document.getElementById("upass")
 var oError = document.getElementById("error_box")
 var isError = true;
 if (oUname.value.length > 20 || oUname.value.length < 6) {
  oError.innerHTML = "用户名请输入6-20位字符";
  isError = false;
  return;
 }else if((oUname.value.charCodeAt(0)>=48) && (oUname.value.charCodeAt(0)<=57)){
  oError.innerHTML = "首字符必须为字母";
  return;
 }else for(var i=0;i<oUname.value.charCodeAt(i);i++){
  if((oUname.value.charCodeAt(i)<48)||(oUname.value.charCodeAt(i)>57) && (oUname.value.charCodeAt(i)<97)||(oUname.value.charCodeAt(i)>122)){
   oError.innerHTML = "必须为字母跟数字组成";
   return;
  }
 }

 if (oUpass.value.length > 20 || oUpass.value.length < 6) {
  oError.innerHTML = "密码请输入6-20位字符"
  isError = false;
  return;
 }
 window.alert("登录成功")
}
Copy after login

Registration interface html code:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>欢迎你,请先登陆!</title>
 <script type="text/javascript" src="../static/jsp/lx.js"></script>
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<p id="container" style="width: 400px" align="center">
 <p id="header" style="background-color: aquamarine">
  <h2 align="center">注册</h2>
 </p>
 <p id="content">
  <p align="center">账号:
   <input id="uname" type="text" name="user" placeholder="账号首字符为字母">
  </p>
  <p align="center">密码:
   <input id="upass" type="password" name="psw" placeholder="请输入密码">
  </p>
  <p id="error_box"><br></p>
  <br>

  <button onclick="fnLogin()" class="btn btn-info">注册</button>
 </p>
 <p style="background-color: aquamarine">
  <i>版权信息@</i>
 </p>
</p>
</body>
</html>
Copy after login

The running results are as follows:

Related recommendations:

Example sharing JavaScript login verification basic tutorial

Detailed explanation of Ajax to achieve beautiful and safe Login interface method

CSS and JS implementation of pop-up login centered interface tutorial

The above is the detailed content of Detailed example of js implementation of login and registration interface. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!