国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

全面解析Bootstrap彈窗的實現(xiàn)方法

2019-11-20 11:06:49
字體:
供稿:網(wǎng)友

一. 結(jié)構(gòu)分析 

  Bootstrap框架中的模態(tài)彈出框,分別運用了“modal”、“modal-dialog”和“modal-content”樣式,而彈出窗真正的內(nèi)容都放置在“modal-content”中,其主要又包括三個部分:

  ☑ 彈出框頭部,一般使用“modal-header”表示,主要包括標題和關(guān)閉按鈕

  ☑ 彈出框主體,一般使用“modal-body”表示,彈出框的主要內(nèi)容

  ☑ 彈出框腳部,一般使用“modal-footer”表示,主要放置操作按鈕

<div class="modal" id="mymodal"> <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">模態(tài)彈出窗標題</h4> </div> <div class="modal-body"> <p>模態(tài)彈出窗主體內(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><!-- /.modal-content --> </div><!-- /.modal-dialog --></div><!-- /.modal -->

二 . data-toggle類觸發(fā)彈窗(無需寫JS)

1 . 模態(tài)彈出窗聲明,只需要自定義兩個必要的屬性:data-toggle和data-target.

<!-- data-target觸發(fā)模態(tài)彈出窗元素 --><button class="btn btn-primary" data-toggle="modal" data-target="#mymodal-data" type="button">通過data-target觸發(fā)</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">×</span><span class="sr-only">Close</span></button> <h4 class="modal-title">模態(tài)彈出窗標題</h4> </div> <div class="modal-body"> <p>模態(tài)彈出窗主體內(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>

2 . data-參數(shù)說明

  除了通過data-toggle和data-target來控制模態(tài)彈出窗之外,Bootstrap框架針對模態(tài)彈出框還提供了其他自定義data-屬性,來控制模態(tài)彈出窗。

 三 . JS觸發(fā)彈窗(要寫JS)

  1 . 除了使用自定義屬性觸發(fā)模態(tài)彈出框之外,還可以通過JavaScript方法來觸發(fā)模態(tài)彈出窗。通過給一個元素一個事件,來觸發(fā)。比如說給一個按鈕一個單擊事件,然后觸發(fā)模態(tài)彈出窗。

HTML:

<button class="btn btn-primary" type="button">點擊我</button><div class="modal" id="mymodal"> <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">模態(tài)彈出窗標題</h4> </div> <div class="modal-body"> <p>模態(tài)彈出窗主體內(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><!-- /.modal-content --> </div><!-- /.modal-dialog --></div><!-- /.modal -->

JS:

 $(function(){ $(".btn").click(function(){ $("#mymodal").modal("toggle"); }); });

2 . 使用JavaScript觸發(fā)模態(tài)彈出窗時,Bootstrap框架提供了一些設(shè)置,主要包括

屬性設(shè)置:

$(function(){ $(".btn").click(function(){ $("#mymodal").modal({ keyboard:false }); });});

參數(shù)設(shè)置:

 事件設(shè)置:

$('#myModal').on('hidden.bs.modal', function (e) { // 處理代碼...})

四 . 彈窗尺寸

Bootstrap框架還為模態(tài)彈出窗提供了不同尺寸.

  一個是大尺寸樣式"modal-lg”.

<divclass="modal-dialog modal-lg"> <divclass="modal-content"> ... </div></div>

  另一個是小尺寸樣式"modal-sm”.

<divclass="modal-dialog modal-sm"> <divclass="modal-content"> ... </div></div>

如果大家還想深入學習,可以點擊這里進行學習,再為大家附兩個精彩的專題:Bootstrap學習教程 Bootstrap實戰(zhàn)教程

以上就是關(guān)于Bootstrap彈窗的實現(xiàn)方法的全部介紹,希望對大家的學習有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 澄迈县| 天峻县| 博兴县| 花莲市| 昆明市| 肇源县| 亚东县| 图们市| 商河县| 田林县| 崇礼县| 双城市| 班玛县| 宕昌县| 苍溪县| 兴国县| 香港 | 内黄县| 涞水县| 都安| 兴山县| 武邑县| 高陵县| 石门县| 江城| 乌兰浩特市| 尤溪县| 杭锦后旗| 弋阳县| 京山县| 安达市| 睢宁县| 东乌珠穆沁旗| 南川市| 轮台县| 开阳县| 平舆县| 乌鲁木齐县| 南部县| 北海市| 西安市|