打开和关闭bootstrap模态

时间:2018-03-01 09:04:00

标签: javascript jquery html twitter-bootstrap bootstrap-modal

GIF PART 1

GIF PART 2

你好,伙计们, 有没有人知道如何制作一个类似于上面GIF图像上的引导模态弹出窗口, 我已经尝试但它没有用。 我的JS代码:

$('#abtn').click(function(){
    $('#aaa').modal('show');
    $('#bbb').modal('hide');
});
$('#bbtn').click(function(){
    $('#bbb').modal('show');
    $('#aaa').modal('hide');
});

2 个答案:

答案 0 :(得分:0)

$(document).ready(function(){
    $("#myBtn").click(function(){
        $("#myModal").modal();
    });
    $("#myBtn1").click(function(){
        $("#myModal1").modal();
    });
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 <button type="button" class="btn btn-info btn-lg" id="myBtn">aaa</button>
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>you clicked aaa</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
  
  <button type="button" class="btn btn-info btn-lg" id="myBtn1">bbb</button>
  <div class="modal fade" id="myModal1" role="dialog">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>you clicked bbb</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>

答案 1 :(得分:0)

它看起来像这样,但我不认为position: fixed要求使它们保持可见,因为模态值得。你应该重新考虑这个想法。

&#13;
&#13;
$('#abtn').click(function(){
    $('.modal').modal('hide');
    $('#aaa').modal('show');
});
$('#bbtn').click(function(){
    $('.modal').modal('hide');
    $('#bbb').modal('show');
});
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<button class="btn btn-primary" id="abtn" style="position: fixed; z-index: 2000;">AAA</button>
<button class="btn btn-primary" id="bbtn" style="position: fixed; left: 4rem; z-index: 2000;">BBBB</button>

<div class="modal fade" id="aaa" tabindex="-1" role="dialog" aria-labelledby="aaaLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="aaaLabel">AAAAA</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        AAAAAAAA
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="bbb" tabindex="-1" role="dialog" aria-labelledby="bbbLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="bbbLabel">BBBBB</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        BBBBBBB
      </div>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;