【发布时间】:2019-02-03 18:21:33
【问题描述】:
<a href="https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_modal&stacked=h" id="leave">click here to leave the page</a>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<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>Changes made may not be saved.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
$("#leave").click(function() {
$(window).bind('beforeunload', function() {
return 'Changes you made may not be Saved';
});
});
【问题讨论】:
-
你不能那样做。
-
我认为最接近你的是stackoverflow.com/questions/20253246/…。或者只是让您检查是否设置了“已保存”变量。
-
您能否确认您是否需要那个“beforeunload”事件,或者它只是举例?如果您不需要它,则可以显示模型,否则不需要。
标签: javascript jquery html css model-view-controller