前端之bootstrap模態框,之bootstrap模態框

來源:互聯網
上載者:User

前端之bootstrap模態框,之bootstrap模態框
  簡介:模態框(Modal)是覆蓋在父表單上的子表單。通常,目的是顯示來自一個單獨的源的內容,可以在不離開父表單的情況下有一些互動。子表單可提供資訊、互動等。

  • Modal簡介
  • Modal實現彈出表單
  • Modal實現刪除提示框
  • 其他用法
Bootstrap 模態框(Modal)外掛程式

模態框(Modal)是覆蓋在父表單上的子表單。通常,目的是顯示來自一個單獨的源的內容,可以在不離開父表單的情況下有一些互動。子表單可提供資訊、互動等。

如果您想要單獨引用該外掛程式的功能,那麼您需要引用 modal.js。或者,正如 Bootstrap 外掛程式概覽 一章中所提到,您可以引用 bootstrap.js 或壓縮版的 bootstrap.min.js
<!DOCTYPE html><html><head>    <meta charset="utf-8">     <title>Bootstrap 執行個體 - 模態框(Modal)外掛程式</title>    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script></head><body><h2>建立模態框(Modal)</h2><!-- 按鈕觸發模態框 --><button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">    開始示範模態框</button><!-- 模態框(Modal) --><div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" 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">                    &times;                </button>                <h4 class="modal-title" id="myModalLabel">                    模態框(Modal)標題                </h4>            </div>            <div class="modal-body">                在這裡添加一些文本            </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><!-- /.modal-content -->    </div><!-- /.modal --></div></body></html>

代碼講解:

  • 使用模態視窗,您需要有某種觸發器。您可以使用按鈕或連結。這裡我們使用的是按鈕。
  • 如果您仔細查看上面的代碼,您會發現在 <button> 標籤中,data-target="#myModal" 是您想要在頁面上載入的模態框的目標。您可以在頁面上建立多個模態框,然後為每個模態框建立不同的觸發器。現在,很明顯,您不能在同一時間載入多個模組,但您可以在頁面上建立多個在不同時間進行載入。
  • 在模態框中需要注意兩點:
  • 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 用於開啟模態視窗。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.