bootstrap弹出层的多种触发方式

bootstrap弹出层有多种触发方式,以下是我用到的几种方式:

1.方法一:

button中属性触发

注意:button中的data-target内容应该和要和弹出层中的id保持一致 data-target=”#mymodal-data”——– id=”mymodal-data”

rush:xhtml;">

<div class="modal" id="mymodal-data" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">×
<span class="sr-only">Close

结果:

这里写图片描述

2.方法二:

通过js绑定

注意:将button的id和弹出层的id分别赋给 $m_btn和$modal,当$m_btn被点击后$modal弹出。

rush:xhtml;">

<div class="modal" id="y-myModalAdd" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">×
<span class="sr-only">Close

结果:

这里写图片描述

这里写图片描述

bootstrap的弹出层在整个屏幕的上半部分,可以将它居中显示。(方法二可以让弹出层居中显示

rush:js;"> $(function(){ // dom加载完毕 var $m_btn = $('#y-modalBtnAdd'); y-modalBtnAdd是button的id var $modal = $('#y-myModalAdd'); y-myModalAdd是弹出的遮罩层的id,通过这两个id进行绑定 // 测试 bootstrap 居中 ,bootstrap的弹出层认是左右居中,上下则是偏上,此代码将弹出层上下也居中了,但是会抖 动一下 $modal.on('shown.bs.modal',function(){ var $this = $(this); var $modal_dialog = $this.find('.modal-dialog'); var m_top = ( $(document).height() - $modal_dialog.height() )/2; $modal_dialog.css({'margin': m_top + 'px auto'}); }); });

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

bootstrapbootstrap弹出层

相关文章

Bootstrip HTML 查询搜索常用格式模版 &lt;form class=&...
如何在按钮上加红色数字 您可以使用Bootstrap的badge组件来在...
要让两个按钮左右排列,你可以使用 Bootstrap 的网格系统将它...
是的,可以将status设置为布尔类型,这样可以在前端使用复选...
前端工程师一般用的是Bootstrap的框架而不是样式,样式一般自...
起步导入:<linkrel="stylesheet"href="b...