$('#abtn').click(function(){
$('#aaa').modal('show');
$('#bbb').modal('hide');
});
$('#bbtn').click(function(){
$('#bbb').modal('show');
$('#aaa').modal('hide');
});
答案 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">×</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">×</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
要求使它们保持可见,因为模态值得。你应该重新考虑这个想法。
$('#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">×</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">×</span>
</button>
</div>
<div class="modal-body">
BBBBBBB
</div>
</div>
</div>
</div>
&#13;