BootStrap学习(6)_模态框_html/css_WEB-ITnose
一、模态框
模态框(Modal)是覆盖在父窗体上的子窗体。通常,目的是显示来自一个单独的源的内容,可以在不离开父窗体的情况下有一些互动。子窗体可提供信息、交互等。
如果只使用该功能,只引入BootStrap中的 modal.js即可
1.用法:
您可以切换模态框(Modal)插件的隐藏内容:
$('#identifier').modal(options)
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title></title> <link href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" /> <script src="http://apps.bdimg.com/libs/jquery/2.0.0/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script></head><body style="margin-top:20px;margin-left:20px;"> <h3 id="创建模态框-Modal">创建模态框(Modal)</h3><!-- 按钮触发模态框 --> <table class="table table-bordered"> <thead> <tr> <th>书名</th> <th>单价</th> <th>操作</th> </tr> </thead> <tbody> <tr> <td>三国演义</td> <td>50</td> <td ><button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"> 修改</button></td> </tr> </tbody></table><!-- 模态框(Modal) --> <form ><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 id="模态框-Modal-标题"> 模态框(Modal)标题 </h4> </div> <div class="modal-body"> <table class="table table-condensed"> <tr><td>书名:<input type="text" value="三国演义"/>价格:<input type="text" value="50" /></td></tr> </table> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">关闭 </button> <button type="button" class="btn btn-primary"> 提交更改 </button> </div> </div> <!-- /.modal-content --></div><!-- /.modal --> </div> </form></body></html>
效果:
代码讲解:
选项: 在点出模态窗的按钮上加上:data-backdrop='static' 可以指定一个静态的背景,当用户点击模态框外部时不会关闭模态框。
2.事件
下表列出了模态框中要用到事件。这些事件可在函数中当钩子使用。
事件 | 描述 | 实例 |
show.bs.modal | 在调用 show 方法后触发。 | $('#identifier').on('show.bs.modal', function () { // 执行一些动作...}) Copy after login |
shown.bs.modal | 当模态框对用户可见时触发(将等待 CSS 过渡效果完成)。 | $('#identifier').on('shown.bs.modal', function () { // 执行一些动作...}) Copy after login |
hide.bs.modal | 当调用 hide 实例方法时触发。 | $('#identifier').on('hide.bs.modal', function () { // 执行一些动作...}) Copy after login |
hidden.bs.modal | 当模态框完全对用户隐藏时触发。 | $('#identifier').on('hidden.bs.modal', function () { // 执行一些动作...}) Copy after login |
show方法:即弹出模态框事件
hide:方法:即关闭模态框事件
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title></title> <link href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" /> <script src="http://apps.bdimg.com/libs/jquery/2.0.0/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script></head><body style="margin-top: 20px; margin-left: 20px;"> <h3 id="创建模态框-Modal">创建模态框(Modal)</h3> <!-- 按钮触发模态框 --> <table class="table table-bordered"> <thead> <tr> <th>书名</th> <th>单价</th> <th>操作</th> </tr> </thead> <tbody> <tr> <td>三国演义</td> <td>50</td> <td> <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" data-backdrop="static"> 修改 </button> </td> </tr> </tbody> </table> <!-- 模态框(Modal) --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="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 id="模态框-Modal-标题">模态框(Modal)标题 </h4> </div> <div class="modal-body"> <table class="table table-condensed"> <tr> <td>书名:<input type="text" value="三国演义" />价格:<input type="text" value="50" /></td> </tr> </table> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal"> 关闭 </button> <button type="button" class="btn btn-primary"> 提交更改 </button> </div> </div> <!-- /.modal-content --> </div> <!-- /.modal --> </div> <script> $(function () { $('#myModal').on('hide.bs.modal', function () { alert('真的要取消修改吗...'); }) });</script></body></html>
效果:
点关闭时会触发事件。
三、提示工具
是基于BootStrap里面的(Tooltip)插件, 如果单单想用这个功能,可以直接用 tooltip.js这个插件.
当您想要描述一个链接的时候,提示工具(Tooltip)就显得非常有用。
1.用法有两种
1.1 通过 data 属性:如需添加一个提示工具(tooltip),只需向一个锚标签添加 data-toggle="tooltip" 即可。锚的 title 即为提示工具(tooltip)的文本。默认情况下,插件把提示工具(tooltip)设置在顶部。
<a href="#" data-toggle="tooltip" title="提示信息">把鼠标停在我的上面</a>
1.2 通过 JavaScript:通过 JavaScript 触发提示工具(tooltip):
$('#identifier').tooltip(options)<br /><strong>注意:</strong> 您必须使用 jquery 激活它(读取 javascript)。使用下面的脚本来启用页面中的所有的提示工具(tooltip):<br />
$(function () { $("[data-toggle='tooltip']").tooltip(); });
左侧的 Tooltip. 顶部的 Tooltip. 底部的 Tooltip. 右侧的 Tooltip 提示工具(Tooltip)插件 - 按钮
<script> $(function () { $("[data-toggle='tooltip']").tooltip(); });</script>
效果:
2.提示工具的方法
方法 | 描述 | 实例 |
Options: .tooltip(options) | 向元素集合附加提示工具句柄。 | $().tooltip(options) Copy after login |
Toggle: .tooltip('toggle') | 切换显示/隐藏元素的提示工具。 | $('#element').tooltip('toggle') Copy after login |
Show: .tooltip('show') | 显示元素的提示工具。 | $('#element').tooltip('show') Copy after login |
Hide: .tooltip('hide') | 隐藏元素的提示工具。 | $('#element').tooltip('hide') Copy after login |
Destroy: .tooltip('destroy') | 隐藏并销毁元素的提示工具。 | $('#element').tooltip('destroy') Copy after login |
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" /> <script src="http://apps.bdimg.com/libs/jquery/2.0.0/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script></head> <body ><div style="padding: 100px 100px 10px;"> <a href="#" class="tooltip-show" data-toggle="tooltip" title="show">Tooltip 方法 show </a><br /><br /> <a href="#" class="tooltip-hide" data-toggle="tooltip" data-placement="left" title="hide">Tooltip 方法 hide </a><br /><br /> <a href="#" class="tooltip-destroy" data-toggle="tooltip" data-placement="top" title="destroy">Tooltip 方法 destroy </a><br /><br /> <a href="#" class="tooltip-toggle" data-toggle="tooltip" data-placement="bottom" title="toggle">Tooltip 方法 toggle </a><br /><br /> <p class="tooltip-options" > <a href="#" data-toggle="tooltip" title="'am Header2">Tooltip 方法 options </a> </p> <script> $(function () { $('.tooltip-show').tooltip('show'); }); $(function () { $('.tooltip-hide').tooltip('hide'); }); $(function () { $('.tooltip-destroy').tooltip('destroy'); }); $(function () { $('.tooltip-toggle').tooltip('toggle'); }); $(function () { $(".tooltip-options a").tooltip({ html: true }); }); </script></div></body></html>
效果:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.
