通过使用模态框效果实现弹出框的登录效果:
效果图:

<form id="formmodal" action="#"> <h3>过渡效果(Transition)模态框插件的使用案例:</h3> <!--按钮触发模态框--> <button class="btn btn-success btn-lg" data-toggle="modal" data-target="#myModal"> 登录<!--模态框--> </button> <!--data-backdrop="static/false"点击模态框外不会关闭默认为关闭--> <!--data-remote="name.htm"默认是false,如果为有效url的话会将页面嵌入到整个模态框 --> <!--data-keyboard="false"是指按键盘上的【esc】无效默认是true则关闭模态框--> <div class="modal fade" data-backdrop="static" data-remote="false" data-keyboard="false" data-show="show" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModelLabel" 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"> <!--模态框标题--> 登录 </h4> </div> <div class="modal-body" style="text-align: center;"> 用户名: <input type="text" id="txtUserName" /><br /> <br /> 密 码:<input type="text" id="txtPassword" /> </div> <div class="modal-footer"> <button type="button" class="btn btn-primary"> 重置 </button> <button type="button" class="btn btn-primary"> 提交</button> </div> </div> </div> </div> </form>
代码讲解[摘录:http://www.runoob.com/bootstrap/bootstrap-modal-plugin.html]:
- 使用模态窗口,您需要有某种触发器。您可以使用按钮或链接。这里我们使用的是按钮。
- 如果您仔细查看上面的代码,您会发现在 <button> 标签中,data-target="#myModal" 是您想要在页面上加载的模态框的目标。您可以在页面上创建多个模态框,然后为每个模态框创建不同的触发器。现在,很明显,您不能在同一时间加载多个模块,但您可以在页面上创建多个在不同时间进行加载。
- 在模态框中需要注意两点:
- 第一是 .modal,用来把 <div> 的内容识别为模态框。
- 第二是 .fade class。当模态框被切换时,它会引起内容淡入淡出。
- aria-labelledby="myModalLabel",该属性引用模态框的标题。
- 属性 aria-hidden="true" 用于保持模态窗口不可见,直到触发器被触发为止(比如点击在相关的按钮上)。
- <div class="modal-header">,modal-header 是为模态窗口的头部定义样式的类。
- class="close",close 是一个 CSS class,用于为模态窗口的关闭按钮设置样式。
- data-dismiss="modal",是一个自定义的 HTML5 data 属性。在这里它被用于关闭模态窗口。
- class="modal-body",是 Bootstrap CSS 的一个 CSS class,用于为模态窗口的主体设置样式。
- class="modal-footer",是 Bootstrap CSS 的一个 CSS class,用于为模态窗口的底部设置样式。
- data-toggle="modal",HTML5 自定义的 data 属性 data-toggle 用于打开模态窗口。