zoukankan      html  css  js  c++  java
  • BootStrap的两种模态框方式

    1.方法一:button中属性触发

    注意:button中的data-target内容应该和要和弹出层中的id保持一致

    data-target=”#mymodal-data”——– id=”mymodal-data”
    <!--在button上绑定触发弹出层的属性-->
     <button class="btn btn-primary delete" data-toggle="modal"
         data-target="#mymodal-data" data-whatever="@mdo">
          修改
    </button>
    <!-- 模态弹出窗内容 -->
    <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>
              <span class="sr-only">Close</span>
            </button>
            <h4 class="modal-title">弹出层标题</h4>
          </div>
          <div class="modal-body">
            <p>弹出层主体内容</p>
          </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>
      </div>
    </div>

    2.方法二:通过js绑定

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

    <button class="btn btn-info" type="button" id="y-modalBtnAdd" > <label >添加</label></button>
    <!-- 模态弹出窗内容 -->
    <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>
              <span class="sr-only">Close</span>
            </button>
            <h4 class="modal-title">弹出层标题</h4>
          </div>
          <div class="modal-body">
            <p>通过js绑定button和弹出层触发</p>
          </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>
      </div>
    </div>
    <!--js代码-->
    <script type="text/javascript">
      $(function(){
        // dom加载完毕
        var $m_btn = $('#y-modalBtnAdd');  //y-modalBtnAdd是button的id
        var $modal = $('#y-myModalAdd');  //y-myModalAdd是弹出的遮罩层的id,通过这两个id进行绑定
        $m_btn.on('click', function(){
          $modal.modal({backdrop: 'static'});
        });
      });
     </script>

    3.方法三:点击表格一行,弹出弹出层

    动态给tr标签加弹出的触发属性

    <!--表格-->
    <table class="table table-bordered " style=" 400px">
      <thead>
        <tr>
          <th>一</th>
          <th>二</th>
          <th>三</th>
        </tr>
      </thead>
      <tbody class="tableBody">
        <tr>
          <td>one</td>
          <td>two</td>
          <td>three</td>
        </tr>
        <tr>
          <td>four</td>
          <td>five</td>
          <td>six</td>
        </tr>
      </tbody>
    </table>
    <!-- 模态弹出窗内容 -->
    <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>
              <span class="sr-only">Close</span>
            </button>
            <h4 class="modal-title">弹出层标题</h4>
          </div>
          <div class="modal-body">
            <p>点击表格一行内容,弹出弹出层</p>
          </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>
      </div>
    </div>
    <!--js代码-->
    <script type="text/javascript">
      $(function () {
        $(".tableBody>tr").each(function () {
          $(this).on("click",function () {
            $(this).attr({"data-toggle":"modal","data-target":"#mymodal-data","data-whatever":"@mdo"});
          })
        });
      });
    </script>
  • 相关阅读:
    熬夜不易,请老范喝杯烈酒
    php开发面试题---PHP为什么不安全,主要有那些安全问题(整理)
    PHP如何进行错误与异常处理(PHP7中的异常处理和之前版本异常处理的区别)
    PHP如何安装redis扩展(Windows下)
    网页实时聊天之PHP如何实现websocket
    C++ primer札记10-继承
    【Android】android图片轮播
    Android开发经验—不要指望类finalize干活的方法做你想要什么
    可以部署在广域网执行QQ高仿版 GG2014 (源代码)
    SNMP WINDOWS系统的命令行工具下载
  • 原文地址:https://www.cnblogs.com/zhaosijia----1234/p/8946882.html
Copyright © 2011-2022 走看看