【登录页面的美化】bootstrap的使用

对bootstrap需要在官网下载应用包,放入我们所写的项目中,然后再导入包,再官网的使用方法中可以找到很多的前端制作模板。

效果显示:

 代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册/登录</title>
    <script src="../vue/vue.min.js"></script>
    <script src="../vue/axios.min.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="../bootstrap/css/bootstrap.css">
    <style>
        .main{
            position: absolute;/*定位 绝对定位*/
            height: 400px;
            top: 50%;
            margin-top: -200px;/*上外边距*/
            background-color: #ce8483;
            border-radius: 30px;
            box-shadow: 10px 10px 10px rgb(162,162,162);
        }
        .title{
            letter-spacing: 5px;
        }
        span{
            color: steelblue;
        }
        body{
            background-image: url("NBA.png");
            background-repeat: no-repeat;
            height: 100%;
            width: 100%;
            overflow: hidden;
            background-size: cover;
        }
    </style>
</head>
<body>
<div id="app" class="main col-md-4 col-md-offset-4">

    <div v-show="!isShow">
        <div class="title col-md-offset-1">
            <h2><small>登录</small></h2>
        </div>
        <hr>
        <div class="form-horizontal col-md-10 col-md-offset-1">
            <input name="method" value="login" type="hidden">
            <div class="form-group">
                <div class="input-group input-group-lg">
                    <div class="input-group-addon">
                        <span class="glyphicon glyphicon-user"></span>
                    </div>
                    <input class="form-control" type="text" @keyup="checkName2" v-model="player.username" placeholder="用户名">
                </div>
            </div>

            <div class="form-group">
                <div class="input-group input-group-lg">
                    <div class="input-group-addon">
                        <span class="glyphicon glyphicon-lock"></span>
                    </div>
                    <input class="form-control" type="text" @keyup="checkPsw2" v-model="player.password" placeholder="密码">
                </div>
            </div>

            <div class="form-group">
                <button class="btn btn-info btn-lg col-md-12 btn_login" @click="login1" :disabled="isLoginDisable">登录</button>
            </div>
            <div class="form-group">
                <p class="col-md-6 col-md-offset-3">没有账号?点击<a href="javascript:void(0)" @click="exchange1">注册</a> </p>
            </div>

        </div>
    </div>

    <div v-show="isShow">
        <div class="title col-md-offset-1">
            <h2><small>注册</small></h2>
        </div>
        <hr>
        <div class="form-horizontal col-md-10 col-md-offset-1">
            <input name="method" value="login" type="hidden">
            <div class="form-group">
                <div class="input-group input-group-lg">
                    <div class="input-group-addon">
                        <span class="glyphicon glyphicon-user"></span>
                    </div>
                    <input type="text" v-model="player.username" @blur="checkName" class="form-control" placeholder="用户名">
                </div>
            </div>

            <div class="form-group">
                <div class="input-group input-group-lg">
                    <div class="input-group-addon">
                        <span class="glyphicon glyphicon-lock"></span>
                    </div>
                    <input type="text" v-model="player.password" @keyup="checkPsw" class="form-control" placeholder="密码">
                </div>
            </div>

            <div class="form-group">
                <button class="btn btn-info btn-lg col-md-12 btn_login"  @click="register1" :disabled="isResDisable">注册</button>
            </div>
            <div class="form-group">
                <p class="col-md-6 col-md-offset-3">已有账号,直接<a href="javascript:void(0)" @click="exchange1">登录</a> </p>
            </div>

        </div>
    </div>
</div>

<!--昵称:<input type="text" @keyup="checkName2" v-model="player.username"><br>
密码:<input type="text" @keyup="checkPsw2" v-model="player.password"><br>
<button @click="login1" :disabled="isLoginDisable">登录</button><br><br><br>
没有账户,请先<a href="javascript:void(0)" @click="exchange1">注册</a>


<div v-show="isShow">
<h2>注册</h2>
昵称:<input type="text" v-model="player.username" @blur="checkName"><br>
密码:<input type="text" v-model="player.password" @keyup="checkPsw"><br>
<button @click="register1" :disabled="isResDisable">注册</button><br><br><br>

已有账号,直接<a href="javascript:void(0)" @click="exchange1">登录</a>
</div>-->



</body>
<script>
    new Vue({
        el:'#app',
        data:{
            player:{
                username:'',
                password:''
            },
            isShow:false,
            isResDisable:false, //false表示不禁用,true表示禁用
            isLoginDisable:false,
            isRegNameExist:false
        },
        methods:{
            exchange1(){
                this.isShow=!this.isShow
            },
            register1(){
                if( this.player.username.trim()&&this.player.password.trim()){  //都不为空
                    this.isResDisable=false  //不禁用
                    axios.get('/playerC?action=register&username='+this.player.username+'&password='+this.player.password)
                        .then((resp)=>{
                            //如果注册成功,显示登录页面
                            if (resp.data.r){
                                this.isShow=!this.isShow
                            }
                            alert(resp.data.msg)
                            //如果注册失败,留在注册页面
                        })
                }else{//昵称或密码有一个为空
                    this.isResDisable=true  //禁用
                }

            },
            checkName(){
                //检查昵称是否已经存在
                if (this.player.username.trim()){
                    //昵称不为空,去数据库查询
                    axios.get('/playerC?action=getByName&username='+this.player.username.trim()).
                    then((resp)=>{
                        if (resp.data){//不为空,数据库中存在该昵称
                            alert('改昵称已被占用,不能注册!')
                            this.isResDisable=true  //禁用

                        }else{//为空,数据库中不存在该昵称
                            this.isResDisable=false  //不禁用

                        }
                    })

                }else{
                    this.isResDisable=true  //禁用
                }
            },
            checkPsw(){
                if (this.player.password.trim()){
                    this.isResDisable=false   //不禁用
                }else {
                    this.isResDisable=true   //禁用
                }
            },
            login1(){
                if (this.player.username.trim()&&this.player.password.trim()){//都不为空
                    this.isLoginDisable=false
                    //登录后端请求
                    axios.get('/playerC?action=login&username='+this.player.username.trim()+'&password='+this.player.password.trim())
                        .then((resp)=>{
                            if (resp.data){//登录成功,去首页
                                location.assign('/')
                            }else{
                                alert('用户名或密码错误,登录失败!')
                            }
                        })
                }else {
                    this.isLoginDisable=true
                }
            },
            checkName2(){
                if (this.player.username.trim()){
                    this.isLoginDisable=false   //不禁用
                }else {
                    this.isLoginDisable=true   //禁用
                }
            },
            checkPsw2(){
                if (this.player.password.trim()){
                    this.isLoginDisable=false   //不禁用
                }else {
                    this.isLoginDisable=true   //禁用
                }
            }
        }
    })
</script>
</html>

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Bootstrap 是一个流行的前端框架,它提供了一系列的 CSS 样式和 JavaScript 组件,使得开发者可以快速地构建具有现代感的 Web 页面。 以下是使用 Bootstrap 对页面进行美化的基本步骤: 1. 引入 Bootstrap 样式文件和 JavaScript 文件。可以直接从 Bootstrap 官网下载或者使用 CDN 引入。 ```html <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css"> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script> ``` 2. 使用 Bootstrap 样式类来定义 HTML 元素的样式。Bootstrap 提供了一系列的样式类,例如按钮、表格、表单等等。 ```html <button class="btn btn-primary">Primary Button</button> <table class="table"> <thead> <tr> <th>Item</th> <th>Price</th> </tr> </thead> <tbody> <tr> <td>Item 1</td> <td>$10</td> </tr> <tr> <td>Item 2</td> <td>$20</td> </tr> </tbody> </table> <form> <div class="form-group"> <label for="exampleInputEmail1">Email address</label> <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email"> <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> </div> <div class="form-group"> <label for="exampleInputPassword1">Password</label> <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password"> </div> <button type="submit" class="btn btn-primary">Submit</button> </form> ``` 3. 使用 Bootstrap 的 JavaScript 组件来实现页面交互效果。Bootstrap 提供了一些常用的组件,例如模态框、滚动条、下拉菜单等等。 ```html <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal"> Launch demo modal </button> <!-- Modal --> <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Modal title</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> ... </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> </div> </div> ``` 以上是基本的步骤,当然还有更多的细节和技巧,需要根据具体情况进行调整和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值