Basics

优质
小牛编辑
112浏览
2023-12-01

描述 (Description)

  • 要创建开关,需要将.switch类添加到元素中。

  • 在开关内添加带有.switch-input类的《input type = "checkbox"》

  • 接下来,您需要使用.switch-paddle类创建《label》

  • 《input》提供唯一ID,并使用for属性将《label》指向《input》 ,这使得交换机可以点击。

  • 在开关标签内使用.show-for-sr类,它是仅用于屏幕阅读器的文本,用于在视觉上屏蔽文本。

例子 (Example)

以下示例演示如何在Foundation中使用switch

<html>
   <head>
      <title>Switch</title>
      <link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/css/foundation.css">
   </head>
   <body>
      <div class = "switch">
         <input class = "switch-input" id = "demoSwitch" type = "checkbox" name = "demoSwitch">
         <label class = "switch-paddle" for = "demoSwitch">
            <span class = "show-for-sr">Switch</span>
         </label>
      </div>
      <script src = "https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/vendor/jquery.min.js"></script>
      <script src = "https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/foundation.min.js"></script>
      <script>
         $(document).ready(function() {
            $(document).foundation();
         })
      </script>
   </body>
</html>