bootstrap 弹出框
程序员文章站
2024-02-01 23:49:10
...
第一种方法:
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title>Bootstrap(弹出框)</title> <link rel="stylesheet" href="css/bootstrap.min.css"> </head> <body> <h1>弹出框(Modal)</h1> <!-- 按钮触发弹出框 --> <button class="btn btn-primary btn-lg" data-toggle="modal" onclick="btn()">弹出框(Modal)按钮</button> <!-- 弹出框(Modal) --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel">弹出框(Modal)标题</h4> </div> <div class="modal-body"> <h5>内容</h5> <h5>内容</h5> <h5>内容</h5> <h5>内容</h5> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button> <button type="button" class="btn btn-primary">保存</button> </div> </div> </div> </div> <script src="js/jquery.min.js"></script> <script src="js/bootstrap.min.js"></script> <script type="text/javascript"> //按钮 function btn(){ //设置标题 $("#myModalLabel").text("TEST"); //显示内容 $("#myModal").modal("show"); } </script> </body> </html>
第二种方法(添加监听):
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title>Bootstrap(弹出框)</title> <link rel="stylesheet" href="css/bootstrap.min.css"> </head> <body> <h1>弹出框(Modal)</h1> <!-- 在 <button> 标签中,data-target="#myModal" 是您想要在页面上加载的模态框的目标。--> <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">弹出框(Modal)按钮</button> <!-- 弹出框(Modal) --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel">弹出框(Modal)标题</h4> </div> <div class="modal-body"> <h5>内容</h5> <h5>内容</h5> <h5>内容</h5> <h5>内容</h5> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button> <button type="button" class="btn btn-primary">保存</button> </div> </div> </div> </div> <script src="js/jquery.min.js"></script> <script src="js/bootstrap.min.js"></script> <script type="text/javascript"> $(function(){ //在弹出框之前触发 $("#myModal").on("show.bs.modal",function(){ alert("内容回显操作!!!"); }); }); </script> </body> </html>