
- Material Design Lite 教程
- MDL - 首頁
- MDL - 概述
- MDL - 環境設定
- MDL - 佈局
- MDL - 網格
- MDL - 標籤頁
- MDL - 頁尾
- MDL - 徽章
- MDL - 按鈕
- MDL - 卡片
- MDL - 進度條
- MDL - 載入動畫
- MDL - 選單
- MDL - 滑塊
- MDL - 複選框
- MDL - 單選按鈕
- MDL - 圖示
- MDL - 開關
- MDL - 資料表
- MDL - 文字欄位
- MDL - 工具提示
- Material Design Lite 資源
- MDL - 快速指南
- MDL - 有用資源
- MDL - 討論
Material Design Lite - 文字欄位
MDL 提供一系列 CSS 類,用於應用各種預定義的視覺和行為增強功能,並顯示不同型別的文字輸入。下表列出了可用的類及其效果。
序號 | 類名及描述 |
---|---|
1 | mdl-textfield 將容器標識為 MDL 元件,並且在“外部”div 元素上是必需的。 |
2 | mdl-js-textfield 為輸入設定基本的 MDL 行為,並且在“外部”div 元素上是必需的。 |
3 | mdl-textfield__input 將元素標識為文字欄位輸入,並且在輸入或文字區域元素上是必需的。 |
4 | mdl-textfield__label 將元素標識為文字欄位標籤,並且對於輸入或文字區域元素的標籤元素是必需的。 |
5 | mdl-textfield--floating-label 應用浮動標籤效果,是可選的;位於“外部”div 元素上。 |
6 | mdl-textfield__error 將 span 標識為 MDL 錯誤訊息,是可選的;位於具有模式的 MDL 輸入元素的 span 元素上。 |
7 | mdl-textfield--expandable 將 div 標識為 MDL 可擴充套件文字欄位容器;用於可擴充套件輸入欄位,並且在“外部”div 元素上是必需的。 |
8 | mdl-button 將標籤標識為 MDL 圖示按鈕;用於可擴充套件輸入欄位,並且在“外部”div 的標籤元素上是必需的。 |
9 | mdl-js-button 為圖示容器設定基本行為;用於可擴充套件輸入欄位,並且在“外部”div 的標籤元素上是必需的。 |
10 | mdl-button--icon 將標籤標識為 MDL 圖示容器;用於可擴充套件輸入欄位,並且在“外部”div 的標籤元素上是必需的。 |
11 | mdl-input__expandable-holder 將容器標識為 MDL 元件;用於可擴充套件輸入欄位,並且在“內部”div 元素上是必需的。 |
12 | is-invalid 在初始載入時將文字欄位標識為無效,mdl-textfield 元素上是可選的。 |
示例
以下示例將幫助您瞭解 mdl-textfield 類的使用方法,以顯示不同型別的文字欄位。
mdl_textfields.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"> <script langauage = "javascript"> function showMessage(value) { document.getElementById("message").innerHTML = value; } </script> </head> <body> <table> <tr><td>Simple Text Field</td><td>Numeric Text Field</td> <td>Disabled Text Field</td></tr> <tr> <td> <form action = "#"> <div class = "mdl-textfield mdl-js-textfield"> <input class = "mdl-textfield__input" type = "text" id = "text1"> <label class = "mdl-textfield__label" for = "text1">Text...</label> </div> </form> </td> <td> <form action = "#"> <div class = "mdl-textfield mdl-js-textfield"> <input class = "mdl-textfield__input" type = "text" pattern = "-?[0-9]*(\.[0-9]+)?" id = "text2"> <label class = "mdl-textfield__label" for = "text2"> Number...</label> <span class = "mdl-textfield__error">Number required!</span> </div> </form> </td> <td> <form action = "#"> <div class = "mdl-textfield mdl-js-textfield"> <input class = "mdl-textfield__input" type = "text" id = "text3" disabled> <label class = "mdl-textfield__label" for = "text3"> Disabled...</label> </div> </form> </td> </tr> <tr><td>Simple Text Field with Floating Label</td> <td>Numeric Text Field with Floating Label</td> <td> </td></tr> <tr> <td> <form action = "#"> <div class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> <input class = "mdl-textfield__input" type = "text" id = "text4"> <label class = "mdl-textfield__label" for = "text4">Text...</label> </div> </form> </td> <td> <form action = "#"> <div class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> <input class = "mdl-textfield__input" type = "text" pattern = "-?[0-9]*(\.[0-9]+)?" id = "text5"> <label class = "mdl-textfield__label" for = "text5"> Number...</label> <span class = "mdl-textfield__error">Number required!</span> </div> </form> </td> <td> </td> </tr> <tr><td>Multiline Text Field</td><td>Expandable Multiline Text Field</td> <td> </td></tr> <tr> <td> <form action = "#"> <div class = "mdl-textfield mdl-js-textfield"> <textarea class = "mdl-textfield__input" type = "text" rows = "3" id = "text7" ></textarea> <label class = "mdl-textfield__label" for = "text7">Lines...</label> </div> </form> </td> <td> <form action = "#"> <div class = "mdl-textfield mdl-js-textfield mdl-textfield--expandable"> <label class = "mdl-button mdl-js-button mdl-button--icon" for = "text8"> <i class = "material-icons">search</i> </label> <div class = "mdl-textfield__expandable-holder"> <input class = "mdl-textfield__input" type = "text" id = "text8"> <label class = "mdl-textfield__label" for = "sample-expandable"> Expandable Input</label> </div> </div> </form> </td> <td> </td> </tr> </table> </body> </html>
結果
驗證結果。