Foundation - 開關



描述

它用於在開啟和關閉狀態之間切換。

示例

以下示例演示了在 Foundation 中使用 switch 的方法 −

<!doctype html>
   <head>
      <meta charset = "utf-8" />
      <meta http-equiv = "x-ua-compatible" content = "ie = edge" />
      <meta name = "viewport" content = "width = device-width, initial-scale = 1.0" />

      <title>Switch</title>

      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/foundation-sites@6.5.1/dist/css/foundation.min.css" crossorigin="anonymous">

    <!-- Compressed JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/vendor/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/foundation-sites@6.5.1/dist/js/foundation.min.js" crossorigin="anonymous"></script>

   </head>

   <body>
      <h2>Switch Example</h2>

      <div class = "switch tiny">
         <input class = "switch-input" id = "switch_tiny" type = "checkbox">
         <label class = "switch-paddle" for = "switch_tiny"></label>
      </div>

      <div class = "switch small">
         <input class = "switch-input" id = "switch_small" type = "checkbox">
         <label class = "switch-paddle" for = "switch_small"></label>
      </div>

      <div class = "switch large">
         <input class = "switch-input" id = "switch_large" type = "checkbox">
         <label class = "switch-paddle" for = "switch_large"></label>
      </div>

      <script>
         $(document).ready(function() {
            $(document).foundation();
         })
      </script>
   </body>
</html>

輸出

讓我們執行以下步驟,看看上面給出的程式碼是如何工作的 −

  • 儲存上述給定的 html 程式碼 switch.html 檔案。

  • 在瀏覽器中開啟此 HTML 檔案,顯示如下所示的輸出。

foundation_kitchen_sink.htm
廣告
© . All rights reserved.