欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

帶你用原生js寫一個簡單的注冊登錄頁面

 更新時間:2023年06月29日 10:52:47   作者:一路向東.  
這篇文章主要給大家介紹了關(guān)于如何使用原生js寫一個簡單的注冊登錄頁面的相關(guān)資料,文中介紹了一個以js驗證表單的簡潔的注冊登錄頁面,需要的朋友可以參考下

1.首先是我們的注冊頁面

這是我們的html骨架 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注冊</title>
</head>
<link rel="stylesheet" href="./css/common.css" rel="external nofollow" >
<style>
    body {
        width: 100%;
        height: 100%;
        background-image: url(./img/RE53tTA.jfif);
        background-repeat: no-repeat;
        background-size: cover;
    }
</style>
<body>
    <div class="header">
        <h2>注冊</h2>
        </span>
        <label for="username"><span>用戶名:</span><input type="text" id="use"></label>
        <br>
        <label for="password"><span>密碼:</span><input type="password" id="pwd"></label>
        <br>
        <label for="password"><span>確認密碼 </span><input type="password" id="pwd2"> </label>
        <br>
        <div>
            <button onclick="login()">注冊</button>
            <button><a href="./登錄.html" rel="external nofollow" >去登錄</a></button>
        </div>
    </div>
</body>
</html>

這是css樣式

* {
  margin: 0;
  padding: 0;
}
a {
  text-decoration: none;
  color: #fff;
  font-size: 18px;
}
.header {
  width: 400px;
  height: 450px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  margin: 100px 0 0 200px;
  padding: 20px;
}
.header h2 {
  font-size: 24px;
  margin-top: 15px;
  color: rgba(255, 255, 255, 0.7);
}
.header > label {
  margin-top: 40px;
  width: 350px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header > label span {
  font-size: 24px;
  color: #fff;
}
.header > label input {
  border-radius: 20px;
  border: 1px solid #ccc;
  padding: 0 20px;
  background-color: rgba(255, 255, 255, 0.6);
  box-sizing: border-box;
  outline: none;
  width: 240px;
  height: 30px;
  font-size: 18px;
}
.header > div {
  margin-top: 30px;
  display: flex;
  justify-content: space-around;
  width: 325px;
}
.header > div button {
  width: 100px;
  height: 30px;
  background: rgba(0, 0, 0, 0.5);
  border: none;
  border-radius: 12px;
  font-size: 18px;
  color: #fff;
}

下面就是我們注冊的js封裝了

這里的函數(shù)調(diào)用直接寫到了html里面的button事件上面了

 <script>
        //獲取用戶名;
        let useA = localStorage.getItem('username');
        console.log(useA);
        //封裝注冊方法
        function login() {
            //獲取事件的value 
            let username = document.querySelector('#use').value;
            let password = document.querySelector('#pwd').value;
            //這里調(diào)用存入本地的數(shù)據(jù)
            Date(username, password);
        }
        //將數(shù)據(jù)存入本地
        function Date(username, password) {
            localStorage.setItem(username, JSON.stringify({
                username,
                password,
                tag: false
            }))
            if (username === '' || password === '') {
                alert('請先注冊');
            }
            //判斷兩次密碼是否一樣
            else if (pwd.value != pwd2.value) {
                //不一樣的話重新輸入
                alert('兩次輸入密碼不一樣 請重新輸入');
            } else {
                //一樣則提示注冊成功
                alert('注冊成功 ! ! !')
            }
        }
    </script>

這就是我的注冊頁面 ,當然各位要是覺得不好看也可以換成自己喜歡的圖片;

2.登陸頁面

到這里當然要寫我們的登錄頁面了,從注冊頁面獲取數(shù)據(jù) 然后調(diào)用

html樣式

<body>
    <div class="header">
        <h2>登錄</h2>
        <label for="username"><span>用戶名:</span><input type="text" id="use"></label>
        <br>
        <label for="password"><span>密碼:</span><input type="password" id="pwd"></label>
        <br>
        <div class="pwsd">
            <input type="checkbox" id="cbx"><span>記住密碼</span>
        </div>
        <div class="del">
            <button onclick="login()">登錄</button>
            <button><a href="./注冊.html" rel="external nofollow" >去注冊</a></button>
        </div>
    </div>
</body>

css樣式

<style>
    a {
        text-decoration: none;
        color: #fff;
    }
    body {
        width: 100%;
        height: 100%;
        background-image: url(./img/RE53r3l.jfif);
        background-repeat: no-repeat;
        background-size: cover;
    }
    .header {
        width: 400px;
        height: 450px;
        background: rgba(0, 0, 0, .2);
        border-radius: 14px;
        display: flex;
        flex-direction: column;
        margin: 100px 0 0 200px;
        padding: 20px;
    }
    h2 {
        font-size: 24px;
        color: #fff;
    }
    label {
        margin-top: 40px;
        width: 350px;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    label>span {
        font-size: 24px;
        color: #fff;
    }
    label>input {
        border-radius: 20px;
        border: 1px solid #ccc;
        padding: 0 20px;
        background-color: rgba(255, 255, 255, .6);
        box-sizing: border-box;
        outline: none;
        width: 240px;
        height: 30px;
        font-size: 18px;
    }
    .del {
        margin-top: 30px;
        display: flex;
        justify-content: space-around;
        width: 325px;
    }
    .pwsd {
        display: flex;
        margin-top: 45px;
    }
    .pwsd>input {
        width: 24px;
        height: 24px;
    }
    .pwsd>span {
        font-size: 18px;
        color: #fff;
        margin-left: 20px;
    }
    button {
        width: 100px;
        height: 40px;
        background: rgba(0, 0, 0, .6);
        border: none;
        border-radius: 12px;
        font-size: 18px;
        color: #fff;
    }
</style>

js樣式

 
        <script>
            let use = document.getElementById('use');
            let pwd = document.getElementById('pwd');
            let cbx = document.getElementById('cbx');
            function login() {
                //登錄
                //取出本地的用戶的值
                let dateUse = localStorage.getItem(use.value);
                console.log(dateUse)
                let dateObj = JSON.parse(dateUse);//將取出的值轉(zhuǎn)化為對象
                console.log(dateObj);
                if (use.value == dateObj.username && pwd.value == dateObj.password) {
                    alert('登陸成功');
                    dateObj.tag = cbx.checked;
                    localStorage.setItem(use.value, JSON.stringify(dateObj));//再將取出的值轉(zhuǎn)化為字符串類型
                    location.;//登錄成功則跳轉(zhuǎn)到百度頁面
                } else {
                    alert('用戶名或者密碼錯誤')
                }
            }
            use.onblur = function () {//用戶失去焦點事件s
                //取出用戶的值
                let res = localStorage.getItem(use.value);
                //將用戶值轉(zhuǎn)化為對象
                res = JSON.parse(res);
                if (res != null && res.tag) {//本地是否有該賬號
                    cbx.checked = true;
                    pwd.value = res.password;
                }
            }
        </script>

樣品展示:

總結(jié)

到此這篇關(guān)于用原生js寫一個簡單的注冊登錄頁面的文章就介紹到這了,更多相關(guān)原生js寫注冊登錄頁面內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論