Bootstrap学习之模态框
2014-03-03 22:19
281 查看
<!DOCTYPE html> <html> <head> <title>Bootstrap 101 Template</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Bootstrap --> <link rel="stylesheet" href="css/bootstrap.css"> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="http://cdn.bootcss.com/jquery/1.10.2/jquery.js"> </script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="js/bootstrap.js"> </script> <script type="text/javaScript"> $(document).ready(function(){ $('#myModal').on('hidden.bs.modal', function (e) { alert("关闭事件"); }) $('#myModal').on('show.bs.modal', function (e) { alert("打开对话框之前事情"); }) }) </script> </head> <body> <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"> Launch demo modal </button> <button type="button" data-toggle="modal" data-target="#myModal" onclick="openSelectDialog()"> 按住button启动对话框 </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 title</h4> </div> <div class="modal-body"> aaaaaaaaaaaaa </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal"> Close </button> <button type="button" class="btn btn-primary"> Save changes </button> </div> </div> <!-- /.modal-content --> </div> <!-- /.modal-dialog --> </div> <!-- /.modal --> </body> </html>
不需写JavaScript代码也可激活模态框。通过在一个起控制器作用的页面元素(例如,按钮)上设置
data-toggle="modal",并使用
data-target="#foo"或
href="#foo"指向特定的模态框即可
事件
Bootstrap的模态框类暴露了一些事件用于截获并执行自己的代码。
事件类型 | 描述 |
---|---|
show.bs.modal | This event fires immediately when the showinstance method is called. If caused by a click, the clicked element is available as the relatedTargetproperty of the event. |
shown.bs.modal | This event is fired when the modal has been made visible to the user (will wait for CSS transitions to complete). If caused by a click, the clicked element is available as the relatedTargetproperty of the event. |
hide.bs.modal | This event is fired immediately when the hideinstance method has been called. |
hidden.bs.modal | This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete) |
相关文章推荐
- JavaScript演示排序算法
- javascript实现10进制转为N进制数
- 2019年开发人员应该学习的8个JavaScript框架
- IE8开发人员工具教程(二)
- MooBox 基于Mootools的对话框插件
- 在flex中执行一个javascript方法的简单方式
- Flex结合JavaScript读取本地路径的方法
- javascript asp教程第六课-- response方法
- javascript asp教程More About Recordsets
- javascript asp教程第十二课---session对象
- javascript asp教程创建数据库连接
- javascript asp教程错误处理
- javascript asp教程第十课--global asa
- javascript asp教程第十一课--Application 对象
- javascript 获取特定的 CSS属性值
- JAVASCRIPT IE 与 FF 中兼容写法记录
- javascript横排竖排标准选项卡效果代码
- javascript prototype,executing,context,closure
- javascript实现的树型下拉框改进版