好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

BootstrapJS插件使用实例(2)

Bootstrap JS插件使用实例(2)-模态对话框 发表于 2013-04-27 17:16 ,已有 2484 次阅读 ,共 8 个评论 本篇文章讨论Bootstrap的js模态对话框插件(bootstrap-modal.js) 先看个简单示例,可直接粘贴运行: view sourceprint? 01. !DOCTYPE html 02. html lang =

Bootstrap JS插件使用实例(2)-模态对话框

发表于 2013-04-27 17:16 ,已有 2484 次阅读 ,共 8 个评论

本篇文章讨论Bootstrap的js模态对话框插件(bootstrap-modal.js)

先看个简单示例,可直接粘贴运行:

view sourceprint?

01.

02. html lang = "en" >

03. head >

04. meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" />

05. title >模态对话框示例 title >

06. link href = "http://www.see-source.com/bootstrap/css/bootstrap.css" rel = "stylesheet" >

07. script type = "text/javascript" src = "http://www.see-source.com/bootstrap/js/jquery.js" > script >

08. script type = "text/javascript" src = "http://www.see-source.com/bootstrap/js/bootstrap-modal.js" > script >

09. head >

10.

11. body >

12. div class = "modal hide" id = "myModal" >

13. div class = "modal-header" >

14. button type = "button" class = "close" data-dismiss = "modal" >× button >

15. h3 >对话框标题 h3 >

16. div >

17. div class = "modal-body" >

18. p >你好... p >

19. div >

20. div class = "modal-footer" >

21. a href = "#" data-dismiss = "modal" class = "btn" >关闭 a >

22. a href = "#" class = "btn btn-primary" >保存 a >

23. div >

24. div >

25.

26. button type = "button" class = "btn" data-toggle = "modal" data-target = "#myModal" >打开对话框 button >

27. body >

28. html >

运行效果:

需要注意:

Bootstrap使用的某些HTML元素和CSS属性需要文档类型为HTML5 doctype。因此这一文档类型必须出现在项目的每个页面的开始部分。

view sourceprint?

1.

2. html lang = "en" >

3. ...

4. html >

下面来对上面的代码进行解析下:

bootstrap.css Bootstrap 样式库,这是必不可少的。

jquery.js 引入jquery,Bootstrap插件是jquery插件,依赖于jquery。

bootstrap-modal.js 模式对话框插件


将上面代码中关于对话框的部分摘出来:

view sourceprint?

01. div class = "modal hide" id = "myModal" >

02. div class = "modal-header" >

03. button type = "button" class = "close" data-dismiss = "modal" >× button >

04. h3 >对话框标题 h3 >

05. div >

06. div class = "modal-body" >

07. p >你好... p >

08.

09. div >

10. div class = "modal-footer" >

11. a href = "#" data-dismiss = "modal" class = "btn" >关闭 a >

12. a href = "#" class = "btn btn-primary" >保存 a >

13. div >

14. div >

bootstrap定义的对话框的结构。.modal样式用于定义整个对话框。对话框内包含三部分:modal-header、modal-body、modal-footer 。与上面的css样式名对应。modal-header主要用于显示标题,还可以带有关闭按钮。modal-body是正文部分,具体内容可自定义,一般可以是提示语,或是个表单。modal-footer主要显示操作按钮,如上面的"关闭"、"保存"。这三部分是一般对话框都具备的结构。


调用方式

1 . 通过data属性触发

我们无须手写javascript即可在页面中触发对话框。只要在某个激发元素上设置 data-toggle="modal" ,然后将 data-target="#foo" 或 href="#foo" 设为某个对话框元素的id,这样点击激发元素就会弹出对话框。

如上面示例中的激发元素:

view sourceprint?

1.

  阅读:39次