溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

js實(shí)現(xiàn)登錄與注冊(cè)界面

發(fā)布時(shí)間:2020-10-26 01:25:59 來源:腳本之家 閱讀:210 作者:yishhaoo 欄目:web開發(fā)

完成登錄與注冊(cè)頁面的HTML+CSS+JS,其中的輸入項(xiàng)檢查包括:

用戶名6-12位

首字母不能是數(shù)字

只能包含字母和數(shù)字

密碼6-12位

注冊(cè)頁兩次密碼是否一致

html代碼:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>歡迎你,請(qǐng)先登陸!</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>
<div class="box">
 <h3>登陸</h3>

 <div class="input_box">
  <input id="uname" type="text" name="user" placeholder="請(qǐng)輸入用戶名">
 </div>
 <div class="input_box">
  <input id="upass" type="password" name="psw" placeholder="請(qǐng)輸入密碼">
 </div>
 <div id="error_box"><br></div>
 <div 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="注冊(cè)"></a>
 </div>



</div>
</body>
</html>

css代碼:

*{
 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 h3{
 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;
}

javascript代碼:

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 = "用戶名請(qǐng)輸入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 = "必須為字母跟數(shù)字組成";
   return;
  }
 }

 if (oUpass.value.length > 20 || oUpass.value.length < 6) {
  oError.innerHTML = "密碼請(qǐng)輸入6-20位字符"
  isError = false;
  return;
 }
 window.alert("登錄成功")
}

注冊(cè)界面html代碼:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>歡迎你,請(qǐng)先登陸!</title>
 <script type="text/javascript" src="../static/jsp/lx.js"></script>
 <link  rel="stylesheet">
</head>
<body>
<div id="container"  align="center">
 <div id="header" >
  <h3 align="center">注冊(cè)</h3>
 </div>
 <div id="content">
  <p align="center">賬號(hào):
   <input id="uname" type="text" name="user" placeholder="賬號(hào)首字符為字母">
  </p>
  <p align="center">密碼:
   <input id="upass" type="password" name="psw" placeholder="請(qǐng)輸入密碼">
  </p>
  <div id="error_box"><br></div>
  <br>

  <button onclick="fnLogin()" class="btn btn-info">注冊(cè)</button>
 </div>
 <div >
  <i>版權(quán)信息@</i>
 </div>
</div>
</body>
</html>

運(yùn)行結(jié)果如下:

js實(shí)現(xiàn)登錄與注冊(cè)界面

js實(shí)現(xiàn)登錄與注冊(cè)界面

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI