Bootstrap对话框使用实例讲解
2016-09-24 14:26
471 查看
使用模态框的弹窗组件需要三层 div 容器元素
分别为 modal(模态声明层) dialog(窗口声明层) content(内容层)
在内容层里面,还有三层,分别为 header(头部)、 body(主体)、 footer(注脚)
一个简单的对话框登陆/注册例子
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="./css/bootstrap.min.css"> <script src="./js/jquery.min.js"></script> <script src="./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 id="loginModal" class="modal fade" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"> <span>×</span> </button> <h4 class="modal-title">会员登录</h4> </div> <div class="modal-body"> <label for="log_uname"> <span>帐号:</span> <input id="log_uname" name="log_uname" type="text" placeholder="input your account"> </label> <br> <label for="log_passwd"> <span>密码:</span> <input id="log_passwd" name="log_passwd" type="password" placeholder="input your password"> </label> </div> <div class="modal-footer"> <button type="button" class="btn btn-primary">登录</button> <button type="button" class="btn btn-warning" data-dismiss="modal">退出</button> </div> </div> </div> </div> <!-- LOGIN MODULE --> <div id="registerModal" class="modal fade" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"> <span>×</span> </button> <h4 class="modal-title">注册会员</h4> </div> <div class="modal-body"> <label for="uname"> <span>帐号:</span> <input id="reg_uname" name="reg_uname" type="text" placeholder="input your account"> </label> <br> <label for="reg_passwd"> <span>密码:</span> <input id="reg_passwd" name="reg_passwd" type="password" placeholder="input your password"> </label> <label for="reg_confirm_passwd"> <span>确认:</span> <input id="reg_confirm_passwd" name="reg_confirm_passwd" type="password" placeholder="confirm your password"> </label> </div> <div class="modal-footer"> <button type="button" class="btn btn-primary">注册</button> <button type="button" class="btn btn-warning" data-dismiss="modal">退出</button> </div> </div> </div> </div> <button class="btn btn-primary" data-toggle="modal" data-target="#loginModal">登陆</button> <button class="btn btn-warning" 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 class="btn btn-lg btn-danger" 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实战教程
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
- 利用BootStrap弹出二级对话框的简单实现方法
- BootStrap+Angularjs+NgDialog实现模式对话框
- 封装的dialog插件 基于bootstrap模态对话框的简单扩展
- Bootstrap编写一个在当前网页弹出可关闭的对话框 非弹窗
- 基于BootStrap Metronic开发框架经验小结【六】对话框及提示框的处理和优化
- Bootstrap模态对话框的简单使用
- 如何使用Bootstrap的modal组件自定义alert,confirm和modal对话框
- JS表格组件神器bootstrap table详解(基础版)
- JS组件Bootstrap实现弹出框和提示框效果代码
- 基于Bootstrap+jQuery.validate实现Form表单验证
相关文章推荐
- Android 对话框 Dialog使用实例讲解
- 使用bootstrap实现下拉框搜索功能的实例讲解
- 实例讲解.NET中资源文件的创建与使用
- 实例讲解.NET中资源文件的创建与使用(转)
- PHP类的使用 实例代码讲解
- C#怎么使用Dictionary?有啥用途实例讲解
- 实例讲解如何使用C++操作MySQL数据库类
- 实例讲解.NET中资源文件的创建与使用
- Msql视图(View)使用实例讲解
- 实例讲解:使用IBM heapAnalyzer分析heap dump文件步骤
- Ext2.0 form使用实例(很详细的讲解,强烈推荐)
- linux窗口程序设计 Qt4精彩实例分析 pyqt实现 实例2 标准对话框的使用
- 实例讲解.NET中资源文件的创建与使用
- 颜色、字体对话框使用实例
- Repeater的复杂使用讲解实例子
- dbus实例讲解(四下):使用dbus-glib
- 实例讲解.NET中资源文件的创建与使用
- 使用autoconf、automake自动生成Makefile实例讲解
- PHP 类 的使用[实例讲解]
- Grub安装、配置以及使用实例汇总讲解