新手必看:从零开始构建实用的表单增删查改(CRUD)系统超全源码!手把手教你实现炫酷的登录注册页面大学生期末大作业指南:HTML/CSS/JavaScript 表单实例轻松实现表单 CRUD:完

b站视频演示效果:

效果图:

完整代码:

<!DOCTYPE html>
<html lang="zh-CN">
<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: linear-gradient(135deg, #89f7fe 0%, #66a6ff 100%);
            display: flex;
            justify-content: center;
            align-items: center;
            font-family: 'Microsoft YaHei', sans-serif;
            color: #333;
        }

        /* 容器 */
        .container {
            width: 100%;
            max-width: 400px;
            background-color: #ffffff;
            border-radius: 15px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
            padding: 40px;
            box-sizing: border-box;
        }

        /* 标题 */
        .title {
            text-align: center;
            font-size: 28px;
            margin-bottom: 30px;
        }

        /* 输入框容器 */
        .input-container {
            position: relative;
            margin-bottom: 20px;
        }

        /* 输入框 */
        .input-container input {
            width: 100%;
            padding: 12px 15px;
            background-color: #f7f9fc;
            border: 1px solid #dfe3e8;
            border-radius: 5px;
            font-size: 16px;
            outline: none;
            box-sizing: border-box;
        }

        /* 输入框占位符颜色 */
        .input-container input::placeholder {
            color: #999;
        }

        /* 发送验证码按钮 */
        .input-with-button {
            position: relative;
        }

        .input-with-button button {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            padding: 8px 12px;
            background-color: #66a6ff;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 12px;
            outline: none;
        }

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

        /* 登录按钮 */
        .login-btn {
            width: 100%;
            padding: 14px;
            background-color: #66a6ff;
            border: none;
            border-radius: 5px;
            font-size: 18px;
            color: #fff;
            cursor: pointer;
            margin-bottom: 20px;
            outline: none;
        }

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

        /* 链接组 */
        .link-group {
            text-align: center;
            margin-top: 10px;
        }

        .link-group a {
            color: #66a6ff;
            text-decoration: none;
            margin: 0 10px;
            font-size: 14px;
        }

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

        /* 提示文本 */
        .note {
            text-align: center;
            font-size: 14px;
            color: #666;
            margin-bottom: 20px;
        }

        /* 响应式 */
        @media (max-width: 400px) {
            .container {
                padding: 30px;
            }
            .title {
                font-size: 24px;
                margin-bottom: 20px;
            }
            .input-container input {
                font-size: 14px;
            }
            .login-btn {
                font-size: 16px;
            }
        }
    </style>
</head>
<body>

<div id="app">
    <div class="container">
        <!-- 登录页面 -->
        <div v-if="currentPage === 'login'">
            <div class="title">欢迎登录</div>

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

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

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

                <div class="link-group">
                    <a href="#" @click.prevent="switchLoginMethod('verification')">使用验证码登录</a>
                    <a href="#" @click.prevent="switchPage('forgotPassword')">忘记密码?</a>
                    <a href="#" @click.prevent="switchPage('register')">注册账号</a>
                </div>
            </div>
        </div>

        <!-- 注册页面 -->
        <div v-else-if="currentPage === 'register'">
            <div class="title">注册账号</div>
            <div class="input-container">
                <input type="text" placeholder="请输入手机号" v-model="registerPhone">
            </div>
            <div class="input-container input-with-button">
                <input type="text" placeholder="请输入验证码" v-model="registerCode">
                <button @click="sendRegisterCode" :disabled="registerCountdown > 0">
                    {{ registerCountdown > 0 ? registerCountdown + '秒' : '获取验证码' }}
                </button>
            </div>
            <div class="input-container">
                <input type="password" placeholder="请输入密码" v-model="registerPassword">
            </div>
            <button class="login-btn" @click="register">注册</button>
            <div class="link-group">
                <a href="#" @click.prevent="switchPage('login')">已有账号?登录</a>
            </div>
        </div>

        <!-- 找回密码页面 -->
        <div v-else-if="currentPage === 'forgotPassword'">
            <div class="title">找回密码</div>
            <div class="input-container">
                <input type="text" placeholder="请输入手机号" v-model="forgotPhone">
            </div>
            <div class="input-container input-with-button">
                <input type="text" placeholder="请输入验证码" v-model="forgotCode">
                <button @click="sendForgotCode" :disabled="forgotCountdown > 0">
                    {{ forgotCountdown > 0 ? forgotCountdown + '秒' : '获取验证码' }}
                </button>
            </div>
            <div class="input-container">
                <input type="password" placeholder="请输入新密码" v-model="newPassword">
            </div>
            <button class="login-btn" @click="resetPassword">重置密码</button>
            <div class="link-group">
                <a href="#" @click.prevent="switchPage('login')">返回登录</a>
            </div>
        </div>

        <!-- 操作提示 -->
        <div class="note" v-if="message">
            {{ message }}
        </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,

            // 提示信息
            message: ''
        },
        methods: {
            switchLoginMethod(method) {
                this.loginMethod = method;
            },
            switchPage(page) {
                this.currentPage = page;
                this.clearMessages();
            },
            login() {
                if (this.loginMethod === 'verification') {
                    if (!this.phoneNumber || !this.verificationCode) {
                        this.showMessage('请输入手机号和验证码');
                    } else {
                        // 登录逻辑
                        this.showMessage('登录成功');
                    }
                } else {
                    if (!this.username || !this.password) {
                        this.showMessage('请输入用户名和密码');
                    } else {
                        // 登录逻辑
                        this.showMessage('登录成功');
                    }
                }
            },
            register() {
                if (!this.registerPhone || !this.registerCode || !this.registerPassword) {
                    this.showMessage('请完整填写注册信息');
                } else {
                    // 注册逻辑
                    this.showMessage('注册成功');
                    this.switchPage('login');
                }
            },
            resetPassword() {
                if (!this.forgotPhone || !this.forgotCode || !this.newPassword) {
                    this.showMessage('请完整填写信息');
                } else {
                    // 重置密码逻辑
                    this.showMessage('密码已重置');
                    this.switchPage('login');
                }
            },
            sendVerificationCode() {
                if (!this.phoneNumber) {
                    this.showMessage('请输入手机号');
                    return;
                }
                if (this.countdown === 0) {
                    // 发送验证码的逻辑
                    this.showMessage('验证码已发送');
                    this.countdown = 60;
                    this.timer = setInterval(() => {
                        if (this.countdown > 0) {
                            this.countdown--;
                        } else {
                            clearInterval(this.timer);
                        }
                    }, 1000);
                }
            },
            sendRegisterCode() {
                if (!this.registerPhone) {
                    this.showMessage('请输入手机号');
                    return;
                }
                if (this.registerCountdown === 0) {
                    // 发送验证码的逻辑
                    this.showMessage('验证码已发送');
                    this.registerCountdown = 60;
                    this.registerTimer = setInterval(() => {
                        if (this.registerCountdown > 0) {
                            this.registerCountdown--;
                        } else {
                            clearInterval(this.registerTimer);
                        }
                    }, 1000);
                }
            },
            sendForgotCode() {
                if (!this.forgotPhone) {
                    this.showMessage('请输入手机号');
                    return;
                }
                if (this.forgotCountdown === 0) {
                    // 发送验证码的逻辑
                    this.showMessage('验证码已发送');
                    this.forgotCountdown = 60;
                    this.forgotTimer = setInterval(() => {
                        if (this.forgotCountdown > 0) {
                            this.forgotCountdown--;
                        } else {
                            clearInterval(this.forgotTimer);
                        }
                    }, 1000);
                }
            },
            showMessage(msg) {
                this.message = msg;
                setTimeout(() => {
                    this.message = '';
                }, 3000);
            },
            clearMessages() {
                this.message = '';
            }
        }
    });
</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、付费专栏及课程。

余额充值