手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >Bootstrap对话框使用实例讲解
Bootstrap对话框使用实例讲解
摘要:使用模态框的弹窗组件需要三层div容器元素分别为modal(模态声明层)dialog(窗口声明层)content(内容层)在内容层里面,还有...

使用模态框的弹窗组件需要三层 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> <> <div id="loginModal" tabindex="-1"> <div> <div> <div> <button type="button" data-dismiss="modal"> <span>×</span> </button> <h4>会员登录</h4> </div> <div> <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> <button type="button">登录</button> <button type="button" data-dismiss="modal">退出</button> </div> </div> </div> </div> <> <div id="registerModal" tabindex="-1"> <div> <div> <div> <button type="button" data-dismiss="modal"> <span>×</span> </button> <h4>注册会员</h4> </div> <div> <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> <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对话框使用实例讲解】相关文章:

微信WeixinJSBridge API使用实例

showModelessDialog()使用详解

JavaScript中的条件判断语句使用详解

js事件监听器用法实例详解

JavaScript中的setUTCDate()方法使用详解

jquery中map函数遍历数组用法实例

jQuery中 prop() attr()使用详解

javaScript中slice函数用法实例分析

JQuery中层次选择器用法实例详解

JavaScript中substring()方法的使用

精品推荐
分类导航