W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
輸入框。
屬性名 | 類型 | 默認(rèn)值 | 說明 | 最低版本 |
---|---|---|---|---|
value | String | 輸入框的初始值,也可以通過setData修改 | 1.0.0 | |
type | String | text | input的類型,詳情見后面的說明 | 1.0.0 |
password | Boolean | false | 是否為密碼輸入 | 1.0.0 |
placeholder | String | 占位字符 | 1.0.0 | |
placeholder-style | String | 占位符的樣式 | 1.0.0 | |
disabled | Boolean | false | 是否禁用 | 1.0.0 |
maxlength | Number | 140 | 最大輸入長(zhǎng)度 | 1.0.0 |
focus | Boolean | false | 獲取焦點(diǎn) | 1.0.0 |
cursor-spacing | Number | 0 | 指定軟鍵盤彈出時(shí),與光標(biāo)的距離是多少,單位是px | 1.0.0 |
cursor | Number | -1 | 指定focus時(shí)的光標(biāo)位置 | 1.0.0 |
selection-start | Number | -1 | 指定focus時(shí)選中片段的起始位置 | 1.0.0 |
selection-end | Number | -1 | 指定focus時(shí)選中片段的結(jié)束位置 | 1.0.0 |
bindinput | EventHandler | 鍵盤輸入時(shí)觸發(fā),e.detail={value, cursor};處理函數(shù)可以直接return 一個(gè)字符串,將替換input框的內(nèi)容。 |
1.0.0 | |
bindfocus | EventHandler | 輸入框聚焦時(shí)觸發(fā),event.detail={value,height},height為軟鍵盤高度 | 1.0.0 | |
bindblur | EventHandler | 輸入框失去焦點(diǎn)時(shí)觸發(fā),event.detail={value} | 1.0.0 | |
bindconfirm | EventHandler | 用戶點(diǎn)擊鍵盤的完成按鈕時(shí)觸發(fā),event.detail={value} | 1.0.0 |
type的取值范圍:
值 | 說明 |
---|---|
text | 文本輸入鍵盤 |
number | 數(shù)字輸入鍵盤 |
digit | 帶小數(shù)點(diǎn)的數(shù)字鍵盤 |
WARNING
避免過于頻繁地在bindinput回調(diào)里執(zhí)行setData({value: ...}),如果想在鍵盤輸入時(shí)改變input框的值,可以直接在bindinput回調(diào)里return一個(gè)字符串
<view class="page-cells page-cells_after-title">
<view class="page-cell page-cell_input">
<input class="page-input"
placeholder="這個(gè)只有在按鈕點(diǎn)擊的時(shí)候才聚焦" focus="{{focus}}" />
</view>
</view>
<view class="btn-area">
<button bindtap="bindButtonTap">使得輸入框獲取焦點(diǎn)</button>
</view>
<view class="page-cells page-cells_after-title">
<view class="page-cell page-cell_input">
<input class="page-input"
placeholder="focus詳情"
bindfocus="onfocus" bindconfirm="onconfirm" />
</view>
</view>
<view class="btn-area">{{focusDetail}}</view>
<view class="page-cells page-cells_after-title">
<view class="page-cell page-cell_input">
<input class="page-input" placeholder="blur測(cè)試" bindblur="onblur" />
</view>
</view>
Page({
data: {
focus: false,
},
bindButtonTap: function (e) {
this.setData({
focus: true,
})
},
onfocus: function (e) {
console.log(e)
this.setData({focusDetail: JSON.stringify(e.detail)})
},
onblur: function (e) {
tt.showToast({title: 'blur'})
},
onconfirm: function (e) {
tt.showToast({title: 'confirm'})
}
})
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: