Bootstrap对话框使用实例讲解

使用模态框的弹窗组件需要三层 div 容器元素

分别为 modal(模态声明层) dialog(窗口声明层) content(内容层)

在内容层里面,还有三层,分别为 header(头部)、 body(主体)、 footer(注脚) 

一个简单的对话框登陆/注册例子

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link href="https://www.jb51.net/article/css/bootstrap.min.css"> <script src="https://www.jb51.net/article/js/jquery.min.js"></script> <script src="https://www.jb51.net/article/js/bootstrap.min.js"></script> <style> .modal-dialog { width: 20%; } .modal-footer, .modal-header { text-align: center; } input { width: 80%; } </style> </head> <body> <!-- LOGIN MODULE --> <div tabindex="-1"> <div> <div> <div> <button type="button" data-dismiss="modal"> <span>&times;</span> </button> <h4>会员登录</h4> </div> <div> <label for="log_uname"> <span>帐号:</span> <input type="text" placeholder="input your account"> </label> <br> <label for="log_passwd"> <span>密码:</span> <input type="password" placeholder="input your password"> </label> </div> <div> <button type="button">登录</button> <button type="button" data-dismiss="modal">退出</button> </div> </div> </div> </div> <!-- LOGIN MODULE --> <div tabindex="-1"> <div> <div> <div> <button type="button" data-dismiss="modal"> <span>&times;</span> </button> <h4>注册会员</h4> </div> <div> <label for="uname"> <span>帐号:</span> <input type="text" placeholder="input your account"> </label> <br> <label for="reg_passwd"> <span>密码:</span> <input type="password" placeholder="input your password"> </label> <label for="reg_confirm_passwd"> <span>确认:</span> <input type="password" placeholder="confirm your password"> </label> </div> <div> <button type="button">注册</button> <button type="button" data-dismiss="modal">退出</button> </div> </div> </div> </div> <button data-toggle="modal" data-target="#loginModal">登陆</button> <button data-toggle="modal" data-target="#registerModal">注册</button> </body> </html>

对话框其他知识

jQuery方式声明对话框

$('#myModal').modal({ show : true, backdrop : false, keyboard : false, remote : 'index.html', });

jQuery方式显示对话框

$('#myBtn').on('click', function () { $('#myModal').modal('show'); });

对话框的事件

show.bs.modal  ==> 在show方法调用时立即触发

shown.bs.modal  ==> 在模态框完全显示出来并且CSS动画完成之后触发

hide.bs.modal ==> 在hide方法调用时 还未关闭隐藏时触发

hidden.bs.modal ==> 在模态框完全隐藏之后并且CSS动画完成之后触发

$('#myModal').on('show.bs.modal', function () { alert('show !'); });

边缘弹出框

<button type="button" data-toggle="popover" title="弹出框" data-content="这是一个弹出框">点击弹出/隐藏弹出框</button> <script> $('button').popover(); </script>

其他方法

$('button').popover('show'); //显示 $('button').popover('hide'); //隐藏 $('button').popover('toggle'); //反转显示和隐藏 $('button').popover('destroy'); //隐藏并销毁

事件

show.bs.popover ==> 在调用show方法时触发

shown.bs.popover ==> 在显示整个弹窗时触发

hide.bs.popover ===> 在调用hide方法时触发

hidden.bs.popover ==> 在完全关闭整个弹出时触发

如果大家还想深入学习,可以点击这里进行学习,再为大家附两个精彩的专题:Bootstrap学习教程 Bootstrap实战教程

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzjgsd.html