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.com/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>

結果

驗證結果。

廣告