简体   繁体   English

Bootstrap Modal不显示登录窗口

[英]Bootstrap Modal is not Displaying Login Window

How do I display a Login Modal using Bootstrap having included a that needs to be done but still it is not displaying. 如何使用Bootstrap显示登录模态,其中包括需要完成的操作,但仍未显示。

enter code here

How do I make this modal to display given the code below: 如何在给出以下代码的情况下显示此模式:

BOOTSTRAP LINKS: 自举链接:

<link href="css/bootstrap.css" rel="stylesheet" />
<link href="css/bootstrap.min.css" rel="stylesheet" />  
<script type="text/javascript" src="js/jquery-3.1.1.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>

MODAL STYLING: 模态样式:

<style>
.modal-header, h4, .close {
    background-color: #5cb85c;
    color: white !important;
    text-align: center;
    font-size: 30px;
}

.modal-footer {
    background-color: #f9f9f9;
}
</style>

Navigation Bar Containing the Link so as to display the Login Modal: 包含链接的导航栏,以显示登录模式:

<nav class="navbar navbar-default ">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="#"> </a>
            </div>
            <div>
                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="#">Departments</a></li>
                    <li><a href="#">Clubs & Sports</a></li>
                    <li><a href="#">Contact US</a></li>
                    <li><a data-toggle="modal" href="#login">Login</a></li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="register.php"><img alt=""   src="images/person2.png">
                            Sign Up</a></li>
                    <li><a href="#"><img alt="" src="images/login2.png">Login</a></li>
                </ul>
            </div>
        </div>
    </nav>

Container For the Login Modal: 登录方式的容器:

<div class="container">

        <div class="modal fade" id="login" role="dialog">
            <div class="modal-dialog">

                <!-- Modal content-->
                <div class="modal-content">
                    <div class="modal-header" style="padding: 35px 50px;">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4>
                            <span class="glyphicon glyphicon-lock"></span> Login
                        </h4>
                    </div>
                    <div class="modal-body" style="padding: 40px 50px;">
                        <form role="form">
                            <div class="form-group">
                                <label for="usrname"><span class="glyphicon glyphicon-user"></span>
                                    Username</label> <input type="text" class="form-control"
                                    id="usrname" placeholder="Enter email">
                            </div>
                            <div class="form-group">
                                <label for="psw"><span class="glyphicon glyphicon-eye-open"></span>
                                    Password</label> <input type="text" class="form-control"
                                    id="psw" placeholder="Enter password">
                            </div>
                            <div class="checkbox">
                                <label><input type="checkbox" value="" checked>Remember me</label>
                            </div>
                            <button type="submit" class="btn btn-success btn-block">
                                <span class="glyphicon glyphicon-off"></span> Login
                            </button>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-danger btn-default pull-left"
                            data-dismiss="modal">
                            <span class="glyphicon glyphicon-remove"></span> Cancel
                        </button>
                        <p>
                            Not a member? <a href="#">Sign Up</a>
                        </p>
                        <p>
                            Forgot <a href="#">Password?</a>
                        </p>
                    </div>
                </div>

            </div>
        </div>

Javascript code to enable the Login Modal: 启用登录模式的Javascript代码:

<script>
$(document).ready(function(){
    $("#login").click(function(){
       $("#myModal").modal();
    });
});
</script>

Your Javascript is trying to address elements that don't exist because they do not have an id, or the wrong id. 您的Javascript试图处理不存在的元素,因为它们没有ID或ID错误。

Try this. 尝试这个。

Add an id to the link that is supposed to bring up the modal. 将ID添加到应该显示模式的链接。

<li><a href="#" id="loginLink"><img alt="" src="images/login2.png">Login</a></li>

This is not required, but I would recommend changing the id of your modal to be more descriptive. 这不是必需的,但我建议您将模式的ID更改为更具描述性。

<div class="modal fade" id="loginModal" role="dialog">

Now adjust your JavaScript to address the correct elements. 现在调整您的JavaScript以解决正确的元素。

$(document).ready(function(){
    $("#loginLink").click(function(){
       $("#loginModal").modal();
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM