亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

bootstrap彈出層的多種觸發(fā)方式

 更新時間:2017年05月10日 08:45:38   作者:米米余  
這篇文章主要為大家詳細介紹了bootstrap彈出層的多種觸發(fā)方式,具有一定的參考價值,感興趣的小伙伴們可以參考一下

bootstrap彈出層有多種觸發(fā)方式,以下是我用到的幾種方式:

1.方法一:button中屬性觸發(fā)

注意:button中的data-target內(nèi)容應(yīng)該和要和彈出層中的id保持一致
data-target=”#mymodal-data”——– id=”mymodal-data”

<!--在button上綁定觸發(fā)彈出層的屬性-->
 <button class="btn btn-primary delete" data-toggle="modal"
  data-target="#mymodal-data" data-whatever="@mdo">
  修改
</button>

<!-- 模態(tài)彈出窗內(nèi)容 -->
<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">&times;</span>
   <span class="sr-only">Close</span>
  </button>
  <h4 class="modal-title">彈出層標題</h4>
  </div>
  <div class="modal-body">
  <p>彈出層主體內(nèi)容</p>
  </div>
  <div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal">關(guān)閉</button>
  <button type="button" class="btn btn-primary">保存</button>
  </div>
 </div>
 </div>
</div>

結(jié)果:

這里寫圖片描述

2.方法二:通過js綁定

注意:將button的id和彈出層的id分別賦給 $m_btn和$modal,當$m_btn被點擊后$modal彈出。

<button class="btn btn-info" type="button" id="y-modalBtnAdd" > <label >添加</label></button>


<!-- 模態(tài)彈出窗內(nèi)容 -->
<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">&times;</span>
   <span class="sr-only">Close</span>
  </button>
  <h4 class="modal-title">彈出層標題</h4>
  </div>
  <div class="modal-body">
  <p>通過js綁定button和彈出層觸發(fā)</p>
  </div>
  <div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal">關(guān)閉</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>

結(jié)果:

這里寫圖片描述

3.方法三:點擊表格一行,彈出彈出層

動態(tài)給tr標簽加彈出的觸發(fā)屬性

<!--表格-->
<table class="table table-bordered " style="width: 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>

<!-- 模態(tài)彈出窗內(nèi)容 -->
<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">&times;</span>
   <span class="sr-only">Close</span>
  </button>
  <h4 class="modal-title">彈出層標題</h4>
  </div>
  <div class="modal-body">
  <p>點擊表格一行內(nèi)容,彈出彈出層</p>
  </div>
  <div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal">關(guān)閉</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>

結(jié)果:

這里寫圖片描述

這里寫圖片描述

bootstrap的彈出層在整個屏幕的上半部分,可以將它居中顯示。(方法二可以讓彈出層居中顯示)

$(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'});
 });
 });
</script>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 淺談JavaScript的push(),pop(),concat()方法

    淺談JavaScript的push(),pop(),concat()方法

    下面小編就為大家?guī)硪黄獪\談JavaScript的push(),pop(),concat()方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-06-06
  • 梳理總結(jié)25個JavaScript數(shù)組操作方法實例

    梳理總結(jié)25個JavaScript數(shù)組操作方法實例

    這篇文章主要分享JavaScript數(shù)組操作方法實例梳理總結(jié),刪除數(shù)組重復(fù)項、獲取數(shù)組的片段等方法,需要的小伙伴可以參考一下
    2022-06-06
  • JavaScript中數(shù)組嵌套對象排序方法的示例詳解

    JavaScript中數(shù)組嵌套對象排序方法的示例詳解

    在?JavaScript?中,可以使用?sort()?方法對包含嵌套對象的數(shù)組進行排序,本文將通過三個簡單的示例為大家進行簡單的介紹,需要的可以參考下
    2024-03-03
  • JS判斷是否在微信瀏覽器打開的簡單實例(推薦)

    JS判斷是否在微信瀏覽器打開的簡單實例(推薦)

    下面小編就為大家?guī)硪黄狫S判斷是否在微信瀏覽器打開的簡單實例(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-08-08
  • 詳解Nuxt.js 實戰(zhàn)集錦

    詳解Nuxt.js 實戰(zhàn)集錦

    這篇文章主要介紹了Nuxt.js 實戰(zhàn)集錦,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧
    2019-11-11
  • js 加載并解析XML字符串的代碼

    js 加載并解析XML字符串的代碼

    js 加載并解析XML字符串的實現(xiàn)代碼,需要的朋友可以參考下。
    2009-12-12
  • JS雙擊變input框批量修改內(nèi)容

    JS雙擊變input框批量修改內(nèi)容

    這篇文章主要介紹了JS雙擊變input框批量修改內(nèi)容的實現(xiàn)代碼,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-12-12
  • js放大鏡放大購物圖片效果

    js放大鏡放大購物圖片效果

    這篇文章主要為大家詳細介紹了基于JavaScript實現(xiàn)放大鏡放大購物圖片效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • 微信小程序Vant組件庫的安裝與使用教程

    微信小程序Vant組件庫的安裝與使用教程

    之前推薦過的移動端web組件庫 Vant是Vue.js版本的,其對內(nèi)承載了有贊所有核心業(yè)務(wù),對外有十多萬開發(fā)者在使用,一直是業(yè)界主流的移動端組件庫之一,下面這篇文章主要給大家介紹了關(guān)于微信小程序Vant組件庫的安裝與使用的相關(guān)資料,需要的朋友可以參考下
    2022-09-09
  • JavaScript中Number的對象解析

    JavaScript中Number的對象解析

    這篇文章主要介紹了JavaScript中Number的對象解析,Number對象是數(shù)值對應(yīng)的包裝對象,可以作為構(gòu)造函數(shù)使用,也可以作為工具函數(shù)使用,感興趣的朋友可以參考一下下面文章內(nèi)容
    2022-08-08

最新評論