简体   繁体   English

Bootstrap 3模式未显示

[英]Bootstrap 3 modal not showing

I have 2 modals in a webpage. 我在网页中有2个模态。 One of them is for registering a new user and the other is for logging in. 其中一个用于注册新用户,另一个用于登录。

Here is there code 这里有代码

<div class="modal fade" id="register" role="dialog" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4>Register</h4>
            </div>
            <div class="modal-body" id="form">
                <div id="form-error-register" class="form-error"></div><br>

                <div class="input-group">
                  <span class="input-group-addon">Username: </span>
                  <input type="text" class="form-control" placeholder="2-20 characters" id="username-register">
                </div>

                <br>

                <div class="input-group">
                  <span class="input-group-addon">Password: </span>
                  <input type="password" class="form-control" placeholder="At least 5 characters" id="password-register">
                </div>

                <br>

                <div class="input-group">
                  <span class="input-group-addon">Confirm Password: </span>
                  <input type="password" class="form-control" placeholder="At least 5 characters" id="cpassword-register">
                </div>

                <br>

                <div class="input-group">
                  <span class="input-group-addon">Email: </span>
                  <input type="text" class="form-control" placeholder="Must be a real email address" id="email-register">
                </div>

            </div>
            <div class="modal-footer">
                <button class="btn btn-danger" onclick="cancelRegister();">Cancel</button>
                <button class="btn btn-success" onclick="registerButton();">Login</button>
            </div>
        </div>
    </div>

    <div class="modal fade" id="login" role="dialog" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4>Login</h4>
            </div>
            <div class="modal-body" id="form">
                <div id="form-error-login" class="form-error"></div><br>

                <div class="input-group">
                  <span class="input-group-addon">Username: </span>
                  <input type="text" class="form-control" placeholder="" id="username-login">
                </div>

                <br>

                <div class="input-group">
                  <span class="input-group-addon">Password: </span>
                  <input type="password" class="form-control" placeholder="" id="password-login">
                </div>

            </div>
            <div class="modal-footer">
                <button class="btn btn-danger" onclick="cancelLogin();">Cancel</button>
                <button class="btn btn-success" onclick="loginButton();">Login</button>
            </div>
        </div>
    </div>

The register modal shows fine but the modal does not. 寄存器模态显示良好,但模态却没有。

Here is the code to show the modals: 这是显示模态的代码:

<li><a href="#register" data-toggle="modal">Register</a></li>
<li><a href="#login" data-toggle="modal">Login</a></li>

This could not be some css error because the register modal loads. 这可能不是某些CSS错误,因为寄存器模态加载。 When I attempt to load the login modal (either via js in the console, or by the button) the webpage goes dark (as if a modal is showing) but the modal never shows. 当我尝试加载登录模式(通过控制台中的js或通过按钮)时,网页变黑(好像正在显示模式),但是模式从未显示。

The #login modal doesn't appear because it's inside the #register modal. #login模式未出现,因为它位于#register模式中。

You should add another div close tag before the #login modal declaration. 您应该在#login模态声明之前添加另一个div close标签。

The reason why the modal is not visible is that its parent, the #register modal, is hidden. 该模式不可见的原因是其父级#register模式已隐藏。

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

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