单击链接关闭并打开新模态

时间:2015-04-15 19:14:12

标签: wordpress twitter-bootstrap modal-dialog

我有两个用bootstrap创建的模式 - 一个用于登录,另一个用于注册。在每个模态中,我有一个链接,我希望它引用另一个模态。例如,注册模式是打开的,注册用户可以单击注册模式内的链接以便登录,反之亦然。 如何在单击登录链接时关闭注册div,然后打开登录div?

这里的完整代码:

https://jsfiddle.net/f9r3ttpw/

这是注册模式的示例启动代码:

<div class="modal modal-backdrop fade" id="myModalJoin" tabindex="-1"
            role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-contentJoin">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-
     label="Close"><span aria-hidden="true">
    <span class="glyphicon glyphicon-remove-sign"></span></button>
    <h2 class="modal-title join" id="myModalLabel"></h2>
    </div>
    <div class="modal-body">

2 个答案:

答案 0 :(得分:0)

Twitter Bootstrap有打开和隐藏模态窗口的选项。您只需要正确调用方法例如

(文档)$。就绪(函数(){

$(".modal1.show").click(function(){
    $("#myModal2").modal('hide');
});

$( “modal2.show”)。单击(函数(){

$( “#myModal1”)模态( '隐藏')。     });

});

答案 1 :(得分:0)

嗨这是工作代码

Java脚本

<script type="text/javascript">
$(document).ready(function(){
  $("#btn1").click(function(){
    $("#myModal").modal('show');
  });

  $("#btn2").click(function(){
    $("#myModal2").modal('show');
  });


  $("#login").click(function(){
    $("#myModal").modal('hide');
    $("#myModal2").modal('show');
  });


  $("#singup").click(function(){
    $("#myModal2").modal('hide');
    $("#myModal").modal('show');
  });

});
</script>

<强> HTML

<div class="bs-example">
    <!-- Button HTML (to Trigger Modal) -->
    <a href="#" id="btn1" class="btn btn-lg btn-primary">sign up</a> <a href="#" id="btn2" class="btn btn-lg btn-primary">login</a>

    <!-- Modal HTML -->
    <div id="myModal" class="modal fade">
        <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>
                    <h4 class="modal-title">Confirmation</h4>
                </div>
                <div class="modal-body">
                    <p>Sign up code here?</p>
                    <p class="text-warning"><small>If you don't save, your changes will be lost.</small></p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                    <button type="button" id="login" class="btn btn-primary">login</button>
                </div>
            </div>
        </div>
    </div>

<div id="myModal2" class="modal fade">
        <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>
                    <h4 class="modal-title">Confirmation</h4>
                </div>
                <div class="modal-body">
                    <p>Login code here?</p>
                    <p class="text-warning"><small>If you don't save, your changes will be lost.</small></p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                    <button type="button" id="singup" class="btn btn-primary">sign up</button>
                </div>
            </div>
        </div>
    </div>

</div>