我一直在寻找解决方案,但似乎没有解决这个问题。
我的代码中有一个模态加载函数脚本,它显示的模态正常,但是当我尝试使用代码中的一个html按钮从data-dismiss =“modal”指令关闭模态时,它doens'nt关闭模态,但如果我点击“打开模态”按钮,那么两个关闭按钮工作正常:
<script>
setTimeout(function(){
$(window).load(function(){
$('#myModal').modal('show');
},3000);
</script>
<div class="container"><!-- Trigger the modal with a button --> <button class="btn btn-info btn-lg" type="button" data-toggle="modal" data-target="#myModal">Open Modal</button> <!-- Modal -->
<div id="myModal" class="modal fade" tabindex="-1">
<div class="modal-dialog"><!-- Modal content-->
<div class="modal-content">
<div class="modal-header"><button class="close" type="button" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer"><button class="btn btn-default" type="button" data-dismiss="modal">Close</button></div>
</div>
</div>
</div>
</div>
所以data-dismiss =“modal”仅在我从“Open Modal”按钮手动加载模态时起作用,但是当我使用load函数在页面加载时显示它时它不起作用。
我会感谢任何帮助,欢迎提出任何建议,
感谢。
答案 0 :(得分:0)
$(window).load(function(){
setTimeout(function(){
$('#myModal').modal('show');
},3000)
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="container"><!-- Trigger the modal with a button --> <button class="btn btn-info btn-lg" type="button" data-toggle="modal" data-target="#myModal">Open Modal</button> <!-- Modal -->
<div id="myModal" class="modal fade" tabindex="-1">
<div class="modal-dialog"><!-- Modal content-->
<div class="modal-content">
<div class="modal-header"><button class="close" type="button" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer"><button class="btn btn-default" type="button" data-dismiss="modal">Close</button></div>
</div>
</div>
</div>
</div>
&#13;