新聞中心
- input 輸入框
- 屬性說明
- type 有效值
- confirm-type 有效值
- 示例
- 代碼示例 1:基礎(chǔ)用法
- 代碼示例 2:自定義輸入控制
- 代碼示例 3:自定義輸入內(nèi)容
- 代碼示例 4:自定義占位符顏色
- 代碼示例 5:實時獲取輸入值
- Bug & Tip
- 屬性說明
input 輸入框
解釋:輸入框。v3.105.0 起支持同層渲染。
Web 態(tài)說明:在 Web 態(tài)中,受瀏覽器限制,部分瀏覽器不支持自動獲取焦點。如:safari 瀏覽器、chrome 瀏覽器;受設備系統(tǒng)或輸入法限制,confirm-type 值無法修改鍵盤右下角按鈕文字,右下角按鈕內(nèi)容由設備系統(tǒng)或輸入法決定。

屬性說明
| 屬性名 | 類型 | 默認值 | 必填 | 說明 | Web 態(tài)說明 |
|---|---|---|---|---|---|
| - | |||||
| - | |||||
| - | |||||
| - | |||||
| - | |||||
| - | |||||
| - | |||||
| - | |||||
| - | |||||
| - | |||||
| - | |||||
| - | |||||
| - | |||||
| - | |||||
| - | |||||
| - |
type 有效值
| 值 | 說明 | Web 態(tài)說明 |
|---|---|---|
| - | ||
| - | ||
confirm-type 有效值
| 值 | 說明 |
|---|---|
請根據(jù)需要錄入的內(nèi)容類型合理設置 input 組件的 type 值,降低用戶操作成本,提升用戶錄入體驗
示例
跳轉(zhuǎn)編輯工具
在開發(fā)者工具中打開
在 WEB IDE 中打開
掃碼體驗
代碼示例
請使用百度APP掃碼
代碼示例 1:基礎(chǔ)用法
- SWAN
- CSS
基礎(chǔ)用法
代碼示例 2:自定義輸入控制
- SWAN
- JS
自定義輸入控制 自動聚焦 placeholder='focus="true"'selection-start="3"selection-end="7"focus="{{true}}"confirm-hold="false"confirm-type="send"bindfocus="bindKeyfocus" />控制長度 cursor="100"bindblur="bindKeyblur"bindconfirm="bindKeyconfirm"placeholder='maxlength="10"'maxlength="10" />禁用 帶有內(nèi)容
代碼示例 3:自定義輸入內(nèi)容
- SWAN
- JS
自定義輸入內(nèi)容 文本 type="text"placeholder='type="text"'bindinput="{{!isWeb ? '': 'keyBoardText'}}"value="{= textValue =}" />數(shù)字 type="number"placeholder='type="number"'bindinput="{{!isWeb ? '': 'keyBoardNumber'}}"value="{= numberValue =}" />身份證 type="idcard"adjust-position="true"placeholder='type="idcard"'bindinput="{{!isWeb ? '': 'keyBoardCard'}}"value="{= cardValue =}" />小數(shù) type="digit"placeholder='type="digit"'bindinput="{{!isWeb ? '': 'keyBoardDigit'}}"value="{= digitValue =}" />
設計指南
錯誤使用 input 組件的 type 值,會額外增加用戶操作成本,影響輸入轉(zhuǎn)化。
錯誤
輸入身份證信息時調(diào)起默認文本鍵盤,用戶需要切換至數(shù)字鍵盤輸入,再切換至字母鍵盤輸入英文字母,共進行 3 次鍵盤切換才能順利完成身份證信息輸入。
代碼示例 4:自定義占位符顏色
- SWAN
自定義占位符顏色 placeholder-style=color:"#3388FF"class="normalInput"placeholder-class="placeholder"placeholder-style="color:#3388FF"placeholder="請在此輸入" />
代碼示例 5:實時獲取輸入值
- SWAN
- JS
實時獲取輸入值 bindinput="bindKeyInput" {{inputValue}}
Bug & Tip
- Tip:input 組件是一個原生組件,字體是系統(tǒng)字體,所以無法設置 font-family 。
- Tip:在 input 聚焦期間,避免使用 CSS 動畫。
- Bug:在 iOS 端鍵盤彈起時會出現(xiàn)組件 bindtap 不生效的問題(部分場景,如:IM 聊天場景中的固定在頁面底部的文本框與發(fā)送按鈕),建議先使用 bindtouchstart 代替 bindtap。
分享題目:創(chuàng)新互聯(lián)百度小程序教程:input 輸入框
本文路徑:http://m.fisionsoft.com.cn/article/djdjpig.html


咨詢
建站咨詢
