简体   繁体   English

如何使用JS更改引导程序模式中的内容

[英]How to use JS to change content in bootstrap modal

I am using twitter bootstrap's modal to make a pop up screen for login. 我正在使用twitter bootstrap的模式来制作弹出屏幕以进行登录。

This is the following code that shows the pop-up form when LOGIN is clicked. 这是下面的代码,显示单击LOGIN时的弹出表单。

<section id="modal-login-form">
        <div class="modal fade" id="m-login" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <p><h4 class="modal-title" id="myModalLabel">Register</h4></p>
                        <button id="login" type="button" class="btn btn-login">Login</button>
                        <button id="register" type="button" class="btn btn-register">Register</button>
                    </div>
                    <div class="modal-body">
                        <p>Username<br>
                        <input class="user" type="text">
                        </p>
                        <p>Password<br>
                        <input class="pass" type="password">
                        </p>
                        <p>Package<br>
                        <input class="package" type="text">
                        </p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-signup">Sign up</button>
                    </div>
                </div>
            </div>
        </div>
    </section>

The above codes produces a caption "Register". 上面的代码产生一个标题“寄存器”。 Two buttons Login and Register below. 下面有两个按钮,登录和注册。 I am trying to make the two buttons dynamic . 我试图使两个按钮动态化 What I am thinking here is that when Login is clicked, the modal will stay there but the body will change dynamically to the login form. 我在这里的想法是, 单击“登录”后,模态将保留在那里,但主体将动态更改为登录表单。 When register is clicked, the body will change dynamically to the register form. 单击寄存器后,主体将动态更改为寄存器形式。

I believe there is javascript involve in this but I can't think of any way to work around this. 我相信这涉及到javascript,但我想不出任何办法解决此问题。 Please enlighten me. 请赐教。 Thanks a lot! 非常感谢!

You should use jquery load() method. 您应该使用jquery load()方法。

Keep the HTML code for login and register in separate files,let me assume it's login.html and register.html . 将用于登录的HTML代码保存在单独的文件中,让我假设它是login.htmlregister.html

  • Assign an id to the modal-body: <div class="modal-body" id="modal"> 为模态主体分配一个ID: <div class="modal-body" id="modal">
  • JS code to load the login html in the modal div: JS代码以在模式div中加载登录html:

     function load_login(){ $( "#modal" ).load( "login.html" ); } 
  • And add an onclick event to the button to load the function: 并在按钮上添加onclick事件以加载函数:

     <button id="login" onclick="load_login()" type="button" class="btn btn-login">Login</button> 

You could do the same for register. 您可以为注册做同样的事情。

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

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