一个简单的登录页面

登录页面

效果展示
在这里插入图片描述

jsp代码
==>body部分,底部有js代码,使用的是vue.js的方法

<body>
    <div id="app">
        <form class="box" action="/login/do_login" method="post">
            <h1>login</h1>
            <input type="text" v-model="username" placeholder="Enter the Username">
            <input type="password" v-model="password" placeholder="Enter the Password">
            <input type="text" v-model="code" placeholder="Enter the code">
            <div>
                <img id="randomCode" alt="验证码" src="/random_code" onclick="changeImg()" style="cursor: pointer;">
            </div>
            <input type="submit" @click="login" value="Login">
            <input type="reset" @click="login" value="Reset">
        </form>
    </div>

    <script type="text/javascript" src="${pageContext.request.contextPath}/static/login/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/login/js/vue/vue.min.js"></script>

    <script type="text/javascript">
        function changeImg() {
            // 拿到当前图片元素
            let randomCode = document.getElementById("randomCode");
            // 修改这张图片的src路径
            // 加上时间戳,因为如果访问路径和之前一样的话,浏览器为认为我们访问了相同的资源,就不会再刷新修改验证码图片
            randomCode.src = "/random_code?date=" + new Date();
        }

        let app = new Vue({
            el: "#app",
            data: {
                username: "",
                password: "",
                info: "",
                code: ""
            },
            methods: {
                login() {
                    let _this = this;
                    $.post("/login/do_login", {
                        username: this.username,
                        password: this.password,
                        code: this.code
                    }, function (data) {
                        if (data.success) {
                            location.replace("/admin/index");
                        } else {
                            if (data.msg) {
                                _this.info = "<span style='background: grey; color: white'>" + data.msg + "</span>";
                            } else {
                                _this.info = "<span style='color: red'>未知错误</span>"
                            }
                        }
                    });
                },
                reset() {
                    this.username = "";
                    this.password = "";
                    this.code = "";
                }
            }
        })
    </script>
</body>

样式部分style.css
==>因为引入style.css失败,原因目前还没找到,就暂时写在页面style标签中了

<style type="text/css">
        body{//清除样式,设置字体和背景
            margin: 0;
            padding: 0;
            font-family: sans-serif;
            background: #34495e;
        }
        .box{
            width: 300px;
            padding: 40px;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            background: #191919;
            text-align: center;
        }
        .box h1{
            color: white;
            text-transform: uppercase;
            font-weight: 500;
        }
        .box input[type ="text"],.box input[type="password"]{
            border: 0;
            background: none;
            display: block;
            margin: 20px auto;
            text-align: center;
            border: 2px solid #3498db;
            padding: 14px 10px;
            width: 200px;
            outline: none;
            color: white;
            border-radius: 24px;
            transition: 0.25s;
        }
        .box input[type ="text"]:focus,.box input[type="password"]:focus {
            width: 280px;
            border-color: #2ecc71;
        }
        .box input[type="submit"]{
            border: 0;
            background: none;
            display: block;
            margin: 20px auto;
            float: left;
            text-align: center;
            border: 2px solid #2ecc71;
            padding: 14px 40px;
            outline: none;
            color: white;
            border-radius: 24px;
            transition: 0.25s;
            cursor: pointer;
        }
       .box input[type="reset"]{
            border: 0;
            background: none;
            display: block;
            margin: 20px auto;
            float: right;
            text-align: center;
            border: 2px solid #2ecc71;
            padding: 14px 40px;
            outline: none;
            color: white;
            border-radius: 24px;
            transition: 0.25s;
            cursor: pointer;
        }
        .box input[type="submit"]:hover{
            background:#2ecc71 ;
        }
        .box input[type="reset"]:hover{
            background:#2ecc71 ;
        }
    </style>

总结:一个简单登录页面,主要是样式设置,js用的是vue.js,主要是加强css认识

好的,以下是一个简单登录界面的前端代码: ```html <!DOCTYPE html> <html> <head> <title>登录界面</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> body { background-color: #f2f2f2; font-family: Arial, sans-serif; } form { background-color: #fff; padding: 20px; box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.2); width: 300px; margin: 0 auto; margin-top: 50px; border-radius: 5px; } h1 { text-align: center; font-size: 30px; color: #444; margin-bottom: 20px; } input[type="text"], input[type="password"] { width: 100%; padding: 10px; margin-bottom: 20px; border-radius: 5px; border: none; box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.2); } input[type="submit"] { background-color: #4CAF50; color: #fff; border: none; padding: 10px; border-radius: 5px; cursor: pointer; width: 100%; font-size: 16px; margin-top: 10px; } input[type="submit"]:hover { background-color: #3e8e41; } </style> </head> <body> <form> <h1>登录</h1> <label for="username">用户名:</label> <input type="text" id="username" name="username" required> <label for="password">密码:</label> <input type="password" id="password" name="password" required> <input type="submit" value="登录"> </form> </body> </html> ``` 这是一个基于 HTML 和 CSS 的简单登录界面,其中包括一个标题、一个用户名输入框、一个密码输入框和一个提交按钮。你可以在自己的项目中使用这段代码,并根据需要进行修改和定制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值