目录

Basics

描述 (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>

输出 (Output)

让我们执行以下步骤,看看上面给出的代码是如何工作的 -

  • 保存上面给出的html代码switch_basics.html文件。

  • 在浏览器中打开此HTML文件,输出显示如下。

新页面打开
↑回到顶部↑
WIKI教程 @2018