Foundation - 無線電開關



說明

無線電開關用於從許多選項中選擇一個選項。可以使用<input type = "radio">來建立選項列表。

示例

以下示例演示如何在 Foundation 中使用無線電開關

<html>
   <head>
      <title>Radio 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>
      <div>
         <div class = "switch">
            <input class = "switch-input" id = "exampleRadioSwitch1" type = "radio" checked name = "testGroup">
            <label class = "switch-paddle" for = "exampleRadioSwitch1">
               <span class = "show-for-sr">Radio Switch 1</span>
            </label>
         </div>

         <div class = "switch">
            <input class = "switch-input" id = "exampleRadioSwitch2" type = "radio" checked name = "testGroup">
            <label class = "switch-paddle" for = "exampleRadioSwitch2">
               <span class = "show-for-sr">Radio Switch 2</span>
            </label>
         </div>

         <div class = "switch">
            <input class = "switch-input" id = "exampleRadioSwitch3" type = "radio" checked name = "testGroup">
            <label class = "switch-paddle" for = "exampleRadioSwitch3">
               <span class = "show-for-sr">Radio Switch 3</span>
            </label>
         </div>
      </div>

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

輸出

讓我們執行以下步驟,瞭解上述程式碼如何工作 -

  • 儲存上述給出的 html 程式碼radio_switch.html檔案。

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

foundation_basic_controls.htm
廣告
© . All rights reserved.