Material Design Lite - 开关



MDL 提供了一系列 CSS 类,可应用各种预定义的可视和行为增强功能,并将不同类型的复选框作为开关显示。下表列出了可用的类及其效果。

序号 类名和描述
1

mdl-switch

将标签标识为 MDL 组件,且标签元素中必需具备此类。

2

mdl-js-switch

为标签设置基本 MDL 行为,且标签元素中必需具备此类。

3

mdl-switch__input

为开关设置基本 MDL 行为,且输入元素(开关)中必需具备此类。

4

mdl-switch__label

为标题设置基本 MDL 行为,且输入元素(标题)中必需具备此类。

5

mdl-js-ripple-effect

设置波纹点击效果,为可选;添加在标签元素上,不在输入元素(开关)上。

示例

以下示例将帮助你了解使用 mdl-switch 类和开关复选框的不同类型。

mdl_switches.htm

<html>
   <head>
      <script 
         src = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.min.js">
      </script>
      <link rel = "stylesheet" 
         href = "https://storage.googleapis.com/code.getmdl.io/1.0.6/material.indigo-pink.min.css">
      <link rel = "stylesheet" 
         href = "https://fonts.googleapis.ac.cn/icon?family=Material+Icons">	  
   </head>
   
   <body>
      <table>
         <tr><td>On Switch</td><td>Off Switch</td>
            <td>Disabled Switch</td></tr>
         <tr>
            <td> 
               <label class = "mdl-switch mdl-js-switch mdl-js-ripple-effect" 
                  for = "switch-1">
                  <input type = "checkbox" id = "switch-1" 
                     class = "mdl-switch__input" checked>
               </label>
            </td>
            
            <td>
               <label class = "mdl-switch mdl-js-switch mdl-js-ripple-effect" 
                  for = "switch-2">
                  <input type = "checkbox" id = "switch-2" 
                     class = "mdl-switch__input">           
               </label>
            </td>
            
            <td>
               <label class = "mdl-switch mdl-js-switch mdl-js-ripple-effect" 
                  for = "switch-2">
                  <input type = "checkbox" id = "switch-2" 
                     class = "mdl-switch__input" disabled>
               </label>
            </td>
         </tr>
      </table>   
   </body>
</html>

结果

验证结果。

广告
© . All rights reserved.