Ionic切换 Ionic表单 Ionic复选框 有时,用户有两种选择。处理这种情况的最有效方法是通过切换表单。Ionic为我们提供了动画和易于实现的切换元素的类。 使用切换 可以使用两个Ionic类来实现切换。首先,我们需要创建一个 标签 ,原因与我们在前一章中解释的相同,并为其分配一个 切换 类。 我们的标签内部将被创建 。 您将注意到以下示例中使用的另外两个Ionic类。该 轨道 时,拨动被窃听类将添加背景的造型给我们的复选框和颜色的动画。该 手柄 类用于圆按钮添加到它。 以下示例显示了两个切换表单。检查第一个,第二个不检查。 <label class = "toggle"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> <br> <label class = "toggle"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> 上面的代码将生成以下屏幕 多个切换 大多数情况下,当您想在Ionic中添加多个相同类型的元素时,最好的方法是使用列表项。用于多次切换的类是 项目切换 。下一个示例显示如何为切换创建列表。检查第一个和第二个。 <ul class = "list"> <li class = "item item-toggle"> Toggle 1 <label class = "toggle"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> </li> <li class = "item item-toggle"> Toggle 2 <label class = "toggle"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> </li> <li class = "item item-toggle"> Toggle 3 <label class = "toggle"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> </li> <li class = "item item-toggle"> Toggle 4 <label class = "toggle"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> </li> </ul> 上面的代码将生成以下屏幕 - 造型切换 所有Ionic颜色类都可以应用于toggle元素。前缀将是 切换 。我们将它应用于 label 元素。以下示例显示了所有应用的颜色。 <ul class = "list"> <li class = "item item-toggle"> Toggle Light <label class = "toggle toggle-light"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> </li> <li class = "item item-toggle"> Toggle Stable <label class = "toggle toggle-stable"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> </li> <li class = "item item-toggle"> Toggle Positiv> <label class = "toggle toggle-positive"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> </li> <li class = "item item-toggle"> Toggle Calm <label class = "toggle toggle-calm"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> </li> <li class = "item item-toggle"> Toggle Balanced <label class = "toggle toggle-balanced"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> </li> <li class = "item item-toggle"> Toggle Energized <label class = "toggle toggle-energized"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> </li> <li class = "item item-toggle"> Toggle Assertive <label class = "toggle toggle-assertive"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> </li> <li class = "item item-toggle"> Toggle Royal <label class = "toggle toggle-royal"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> </li> <li class = "item item-toggle"> Toggle Dark <label class = "toggle toggle-dark"> <input type = "checkbox" /> <div class = "track"> <div class = "handle"></div> </div> </label> </li> </ul> 上面的代码将生成以下屏幕 Ionic表单 Ionic复选框