shown.bs.modal Bootstrap 事件
Bootstrap 中的 shown.bs.modal 事件在模态完全显示时触发。
此处,单击按钮时会生成模态。以下是我们的按钮 −
<button type="button" class="btn btn-default btn-lg" id="button1"> Result </button>
以下是如何在单击按钮时生成模态的脚本 −
$("#button1").click(function(){ $("#newModal").modal("show"); });
现在将在模态对访客可见后使用 shown.bs.modal 事件生成警告 −
$("#newModal").on('shown.bs.modal', function () { alert('The modal is displayed completely!'); });
以下是学习如何实现 shown.bs.modal Bootstrap 事件的完整代码 −
示例
<!DOCTYPE html> <html> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <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> </head> <body> <div class="container"> <h2>Entrance Exams</h2> <p>The following is the result of the entrance exams:</p> <button type="button" class="btn btn-default btn-lg" id="button1">Click for Result</button> <div class="modal fade" id="newModal" 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">Selected</h4> </div> <div class="modal-body"> <p>Rahul, Amit and Shweta cleared the exam.</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button> </div> </div> </div> </div> </div> <script> $(document).ready(function(){ $("#button1").click(function(){ $("#newModal").modal("show"); }); $("#newModal").on('shown.bs.modal', function () { alert('The modal is displayed completely!'); }); }); </script> </body> </html>
广告