零基础教程:用 HTML、CSS 和 JavaScript 构建完整登录注册页面(附源代码)前端新手必看:手把手教你实现表单增删查改(CRUD)功能大学生期末大作业神器:纯前端实现实用登录系统从

b站视频演示效果:

效果图:

完整代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
    <style>
        body, html {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
            /* 更换背景为深色主题 */
            background-color: #1e1e1e;
            display: flex;
            justify-content: center;
            align-items: center;
            font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
        }

        .login-container {
            width: 100%;
            max-width: 400px;
            background-color: #2e2e2e;
            border-radius: 10px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
            padding: 30px;
            color: #fff;
        }

        .logo {
            display: flex;
            justify-content: center;
            margin-bottom: 30px;
        }

        .logo img {
            width: 80px;
        }

        .title {
            text-align: center;
            font-size: 28px;
            color: #fff;
            margin-bottom: 30px;
        }

        .input-container {
            display: flex;
            flex-direction: column;
            margin-bottom: 25px;
            position: relative;
        }

        .input-container input {
            padding: 12px;
            margin: 10px 0;
            border-radius: 5px;
            border: none;
            font-size: 16px;
            width: 100%;
            box-sizing: border-box;
            background-color: #3e3e3e;
            color: #fff;
        }

        .input-container input::placeholder {
            color: #bbb;
        }

        .login-btn {
            background-color: #ff5722;
            color: white;
            padding: 12px;
            width: 100%;
            border: none;
            border-radius: 5px;
            font-size: 18px;
            cursor: pointer;
            margin-bottom: 25px;
        }

        .login-btn:hover {
            background-color: #e64a19;
        }

        .third-party-login {
            display: flex;
            justify-content: space-between;
            margin: 30px 0;
        }

        .third-party-login button {
            flex: 1;
            background-color: #3e3e3e;
            padding: 12px;
            margin: 0 10px;
            border-radius: 5px;
            border: none;
            cursor: pointer;
            font-size: 16px;
            color: #fff;
        }

        .third-party-login button:hover {
            background-color: #4e4e4e;
        }

        .switch-method {
            text-align: center;
            color: #ff5722;
            cursor: pointer;
            margin-top: 15px;
        }

        .switch-method:hover {
            text-decoration: underline;
        }

        .forgot-password {
            text-align: right;
            margin-top: -15px;
            margin-bottom: 15px;
        }

        .forgot-password a {
            color: #ff5722;
            text-decoration: none;
            font-size: 14px;
        }

        .forgot-password a:hover {
            text-decoration: underline;
        }

        .register-link {
            text-align: center;
            margin-top: 15px;
        }

        .register-link a {
            color: #ff5722;
            text-decoration: none;
        }

        .register-link a:hover {
            text-decoration: underline;
        }

        .input-with-button {
            position: relative;
        }

        .input-with-button input {
            width: 100%;
            padding-right: 130px;
        }

        .input-with-button button {
            position: absolute;
            right: 10px;
            top: 12px;
            padding: 8px 16px;
            background-color: #ff5722;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 12px;
        }

        .input-with-button button:disabled {
            background-color: #9e9e9e;
            cursor: not-allowed;
        }

        /* 新增:添加输入框的图标 */
        .input-container .input-icon {
            position: absolute;
            left: 10px;
            top: 50%;
            transform: translateY(-50%);
            color: #bbb;
        }

        .input-container input {
            padding-left: 40px;
        }

        /* 修改按钮样式 */
        .third-party-login button {
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .third-party-login button img {
            width: 20px;
            height: 20px;
            margin-right: 8px;
        }
    </style>
</head>
<body>

<div id="app">
    <div class="login-container">
        <!-- 登录页面 -->
        <div v-if="currentPage === 'login'">
            <div class="logo">
                <img src="https://via.placeholder.com/80" alt="Logo">
            </div>
            <div class="title">欢迎回来!</div>

            <!-- 验证码登录 -->
            <div v-if="loginMethod === 'verification'">
                <div class="input-container">
                    <span class="input-icon">📱</span>
                    <input type="text" placeholder="请输入手机号" v-model="phoneNumber">
                </div>
                <div class="input-container input-with-button">
                    <span class="input-icon">🔑</span>
                    <input type="text" placeholder="请输入验证码" v-model="verificationCode">
                    <button @click="sendVerificationCode" :disabled="countdown > 0">
                        {{ countdown > 0 ? countdown + 's后重发' : '获取验证码' }}
                    </button>
                </div>
                <button class="login-btn" @click="login">登 录</button>

                <div class="forgot-password">
                    <a href="#" @click.prevent="switchPage('forgotPassword')">忘记密码?</a>
                </div>

                <div class="third-party-login">
                    <button @click="thirdPartyLogin('wechat')">
                        <img src="https://via.placeholder.com/20/09f/fff.png" alt="微信"> 微信
                    </button>
                    <button @click="thirdPartyLogin('alipay')">
                        <img src="https://via.placeholder.com/20/00a/fff.png" alt="支付宝"> 支付宝
                    </button>
                </div>

                <div class="switch-method" @click="switchLoginMethod('password')">使用密码登录</div>
                <div class="register-link">
                    没有账号?<a href="#" @click.prevent="switchPage('register')">立即注册</a>
                </div>
            </div>

            <!-- 密码登录 -->
            <div v-else>
                <div class="input-container">
                    <span class="input-icon">👤</span>
                    <input type="text" placeholder="请输入手机号或邮箱" v-model="username">
                </div>
                <div class="input-container">
                    <span class="input-icon">🔒</span>
                    <input type="password" placeholder="请输入密码" v-model="password">
                </div>
                <button class="login-btn" @click="login">登 录</button>

                <div class="forgot-password">
                    <a href="#" @click.prevent="switchPage('forgotPassword')">忘记密码?</a>
                </div>

                <div class="third-party-login">
                    <button @click="thirdPartyLogin('wechat')">
                        <img src="https://via.placeholder.com/20/09f/fff.png" alt="微信"> 微信
                    </button>
                    <button @click="thirdPartyLogin('alipay')">
                        <img src="https://via.placeholder.com/20/00a/fff.png" alt="支付宝"> 支付宝
                    </button>
                </div>

                <div class="switch-method" @click="switchLoginMethod('verification')">使用验证码登录</div>
                <div class="register-link">
                    没有账号?<a href="#" @click.prevent="switchPage('register')">立即注册</a>
                </div>
            </div>
        </div>

        <!-- 注册页面 -->
        <div v-else-if="currentPage === 'register'">
            <div class="logo">
                <img src="https://via.placeholder.com/80" alt="Logo">
            </div>
            <div class="title">创建新账户</div>
            <div class="input-container">
                <span class="input-icon">📱</span>
                <input type="text" placeholder="请输入手机号" v-model="registerPhone">
            </div>
            <div class="input-container input-with-button">
                <span class="input-icon">🔑</span>
                <input type="text" placeholder="请输入验证码" v-model="registerCode">
                <button @click="sendRegisterCode" :disabled="registerCountdown > 0">
                    {{ registerCountdown > 0 ? registerCountdown + 's后重发' : '获取验证码' }}
                </button>
            </div>
            <div class="input-container">
                <span class="input-icon">🔒</span>
                <input type="password" placeholder="请输入密码" v-model="registerPassword">
            </div>
            <button class="login-btn" @click="register">注 册</button>
            <div class="switch-method" @click="switchPage('login')">已有账号?立即登录</div>
        </div>

        <!-- 找回密码页面 -->
        <div v-else-if="currentPage === 'forgotPassword'">
            <div class="logo">
                <img src="https://via.placeholder.com/80" alt="Logo">
            </div>
            <div class="title">找回密码</div>
            <div class="input-container">
                <span class="input-icon">📱</span>
                <input type="text" placeholder="请输入手机号" v-model="forgotPhone">
            </div>
            <div class="input-container input-with-button">
                <span class="input-icon">🔑</span>
                <input type="text" placeholder="请输入验证码" v-model="forgotCode">
                <button @click="sendForgotCode" :disabled="forgotCountdown > 0">
                    {{ forgotCountdown > 0 ? forgotCountdown + 's后重发' : '获取验证码' }}
                </button>
            </div>
            <div class="input-container">
                <span class="input-icon">🔒</span>
                <input type="password" placeholder="请输入新密码" v-model="newPassword">
            </div>
            <button class="login-btn" @click="resetPassword">重置密码</button>
            <div class="switch-method" @click="switchPage('login')">返回登录</div>
        </div>

    </div>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            currentPage: 'login',  // 当前页面:login、register、forgotPassword
            loginMethod: 'verification',  // 登录方式:verification、password

            // 登录数据
            phoneNumber: '',
            verificationCode: '',
            username: '',
            password: '',
            countdown: 0,
            timer: null,

            // 注册数据
            registerPhone: '',
            registerCode: '',
            registerPassword: '',
            registerCountdown: 0,
            registerTimer: null,

            // 找回密码数据
            forgotPhone: '',
            forgotCode: '',
            newPassword: '',
            forgotCountdown: 0,
            forgotTimer: null,
        },
        methods: {
            switchLoginMethod(method) {
                this.loginMethod = method;
            },
            switchPage(page) {
                this.currentPage = page;
            },
            login() {
                if (this.loginMethod === 'verification') {
                    alert(`手机号:${this.phoneNumber}, 验证码:${this.verificationCode}`);
                } else {
                    alert(`用户名:${this.username}, 密码:${this.password}`);
                }
            },
            register() {
                alert(`手机号:${this.registerPhone}, 验证码:${this.registerCode}, 密码:${this.registerPassword}`);
            },
            resetPassword() {
                alert(`手机号:${this.forgotPhone}, 验证码:${this.forgotCode}, 新密码:${this.newPassword}`);
            },
            sendVerificationCode() {
                if (this.countdown === 0) {
                    // 发送验证码的逻辑
                    alert('验证码已发送');
                    this.countdown = 60;
                    this.timer = setInterval(() => {
                        if (this.countdown > 0) {
                            this.countdown--;
                        } else {
                            clearInterval(this.timer);
                        }
                    }, 1000);
                }
            },
            sendRegisterCode() {
                if (this.registerCountdown === 0) {
                    // 发送验证码的逻辑
                    alert('验证码已发送');
                    this.registerCountdown = 60;
                    this.registerTimer = setInterval(() => {
                        if (this.registerCountdown > 0) {
                            this.registerCountdown--;
                        } else {
                            clearInterval(this.registerTimer);
                        }
                    }, 1000);
                }
            },
            sendForgotCode() {
                if (this.forgotCountdown === 0) {
                    // 发送验证码的逻辑
                    alert('验证码已发送');
                    this.forgotCountdown = 60;
                    this.forgotTimer = setInterval(() => {
                        if (this.forgotCountdown > 0) {
                            this.forgotCountdown--;
                        } else {
                            clearInterval(this.forgotTimer);
                        }
                    }, 1000);
                }
            },
            thirdPartyLogin(platform) {
                alert(`第三方登录:${platform}`);
            }
        }
    });
</script>

</body>
</html>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

各位同学们:还有啥想看的功能或者特效不?欢迎在评论区留言哦!

本人承接网网站开发,如有需要,欢迎私信咨询!

如果您感觉文章对您有帮助~
那就打赏一下,请笔者喝杯咖啡吧~

给新手学习前端开发的建议:

  1. 了解基础知识

    • 学习HTML、CSS和JavaScript的基础知识。它们是前端开发的核心,构成了网页的基本结构和样式,以及交互功能。
    • 掌握HTML的标签和语义化,了解CSS的选择器和布局技巧,熟悉JavaScript的基本语法和DOM操作。
  2. 实践项目

    • 不要仅仅停留在理论学习上,通过实践项目来巩固和应用所学知识。
    • 可以从简单的静态页面开始,逐渐尝试添加交互效果和动态数据。
    • 参与开源项目或自己动手创建一个个人网站,将所学知识应用到实际场景中。
  3. 学习工具和框架

    • 了解并学习前端开发中常用的工具和框架,如构建工具(Webpack、Gulp等)、版本控制工具(Git)、前端框架(React、Vue、Angular等)。
    • 这些工具和框架能够提高开发效率,简化开发流程,是前端开发的重要组成部分。
  4. 关注前端趋势

    • 前端开发是一个快速发展的领域,新的技术和工具不断涌现。
    • 关注前端社区、博客和会议,了解最新的技术趋势和发展方向,保持学习的热情和动力。
  5. 培养解决问题的能力

    • 前端开发常常会遇到各种问题和挑战,学会独立思考和解决问题是非常重要的。
    • 遇到问题时,可以先尝试自己解决,通过查阅文档、搜索资料和社区讨论来找到答案。
    • 如果实在无法解决,可以向同事或社区求助,但也要学会总结和分享自己的经验和教训。
  6. 不断学习和提升

    • 前端开发是一个不断学习和提升的过程,要保持对知识的渴望和追求。
    • 可以通过阅读书籍、参加培训、参与开源项目等方式来不断提升自己的技能水平。
    • 同时,也要关注自己的职业发展,了解行业的需求和趋势,规划自己的职业道路。
  7. 注重代码质量和可维护性

    • 编写高质量的代码是前端开发的基本要求之一。
    • 学习并遵循代码规范,使用适当的命名和注释来提高代码的可读性。
    • 注重代码的结构和逻辑,避免过度嵌套和复杂的逻辑。
    • 考虑代码的可维护性,尽量编写可复用和可扩展的代码。
  8. 参与社区和交流

    • 加入前端开发的社区和论坛,与其他开发者进行交流和分享。
    • 通过参与社区活动、回答问题、分享经验等方式,不仅可以提升自己的技能水平,还可以结识更多的同行和朋友。

总之,学习前端开发需要耐心和毅力,要保持对技术的热情和兴趣,不断学习和提升自己。通过实践项目、学习工具和框架、关注前端趋势等方式,你可以逐渐成为一名优秀的前端开发者。

加油吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

南北极之间

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值