W3Cschool
恭喜您成為首批注冊(cè)用戶(hù)
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
解釋?zhuān)狠斎肟颍╲3.105.0 起支持同層渲染)。
屬性名 | 類(lèi)型 | 默認(rèn)值 | 必填 | 說(shuō)明 | Web 態(tài)說(shuō)明 | ||
---|---|---|---|---|---|---|---|
value |
String |
否 |
輸入框的初始內(nèi)容。若要?jiǎng)討B(tài)設(shè)置輸入框內(nèi)容,需設(shè)置 |
- | |||
type |
String |
text |
否 |
input 的類(lèi)型 |
- | ||
password |
Boolean |
false |
否 |
是否是密碼類(lèi)型 |
- | ||
placeholder |
String |
否 |
輸入框?yàn)榭諘r(shí)占位符 |
- | |||
placeholder-style |
String |
否 |
placeholder 的樣式 |
- | |||
placeholder-class |
String |
input-placeholder |
否 |
placeholder 的樣式類(lèi) |
- | ||
disabled |
Boolean |
false |
否 |
是否禁用 |
- | ||
maxlength |
Number |
140 |
否 |
最大輸入長(zhǎng)度,設(shè)置為 -1 的時(shí)候不限制最大長(zhǎng)度 |
- | ||
cursor-spacing |
Number |
0 |
否 |
指定光標(biāo)與鍵盤(pán)的距離,單位 px。 當(dāng)鍵盤(pán)彈出時(shí), 如果需要頁(yè)面上滑才能完整顯示 input 組件, 那么此時(shí)光標(biāo)與鍵盤(pán)的距離為設(shè)定的 cursor-spacing 值; 如果 input 組件處于屏幕上方,鍵盤(pán)彈出時(shí)不會(huì)擋住 input, 則忽略該屬性。 |
受限于設(shè)備系統(tǒng),暫不支持 |
||
focus |
Boolean |
false |
否 |
獲取焦點(diǎn),調(diào)起鍵盤(pán)。
|
部分瀏覽器下不支持自動(dòng)獲取焦點(diǎn) |
||
confirm-type |
String |
done |
否 |
設(shè)置鍵盤(pán)右下角按鈕的文字 |
暫不支持 |
||
confirm-hold |
Boolean |
false |
否 |
點(diǎn)擊鍵盤(pán)右下角按鈕時(shí)是否保持鍵盤(pán)不收起 |
- | ||
cursor |
Number |
否 |
指定 focus 時(shí)的光標(biāo)位置
|
- | |||
selection-start |
Number |
-1 |
否 |
光標(biāo)起始位置,自動(dòng)聚焦時(shí)有效,需與 selection-end 搭配使用 |
- | ||
selection-end |
Number |
-1 |
否 |
光標(biāo)結(jié)束位置,自動(dòng)聚焦時(shí)有效,需與 selection-start 搭配使用 |
- | ||
adjust-position |
Boolean |
true |
否 |
鍵盤(pán)彈起時(shí),是否自動(dòng)上推頁(yè)面 |
受限于設(shè)備系統(tǒng),暫不支持 |
||
bindinput |
EventHandle |
否 |
當(dāng)鍵盤(pán)輸入時(shí),觸發(fā) input 事件,event.detail = {value, cursor, keyCode},keyCode 為鍵值。 |
- | |||
bindfocus |
EventHandle |
否 |
輸入框聚焦時(shí)觸發(fā),event.detail = {value: value, height: height}, height 為鍵盤(pán)高度 |
- | |||
bindblur |
EventHandle |
否 |
輸入框失去焦點(diǎn)時(shí)觸發(fā),event.detail = {value: value} |
- | |||
bindconfirm |
EventHandle |
否 |
點(diǎn)擊完成按鈕時(shí)觸發(fā),event.detail = {value: value} |
- |
值 | 說(shuō)明 | Web 態(tài)說(shuō)明 | ||
---|---|---|---|---|
text |
文本輸入鍵盤(pán) |
- | ||
number |
數(shù)字輸入鍵盤(pán) |
- | ||
idcard |
身份證輸入鍵盤(pán) |
受設(shè)備系統(tǒng)或輸入法限制,一些設(shè)備(如,帶原生輸入法的 iOS 設(shè)備)不支持 |
||
digit |
帶小數(shù)點(diǎn)的數(shù)字鍵盤(pán) |
受設(shè)備系統(tǒng)或輸入法限制,一些設(shè)備(如,帶原生輸入法的 iOS 設(shè)備)不支持 |
Web 態(tài)說(shuō)明:Web 態(tài)下,受設(shè)備系統(tǒng)或輸入法限制,confirm-type 值無(wú)法修改鍵盤(pán)右下角按鈕文字。右下角按鈕內(nèi)容由設(shè)備系統(tǒng)或輸入法決定。
值 | 說(shuō)明 |
---|---|
send |
鍵盤(pán)右下角按鈕為 “發(fā)送” |
search |
鍵盤(pán)右下角按鈕為 “搜索” |
next |
鍵盤(pán)右下角按鈕為 “下一個(gè)” |
go |
鍵盤(pán)右下角按鈕為 “前往” |
done |
鍵盤(pán)右下角按鈕為 “完成” |
代碼示例 1: 基礎(chǔ)用法
<view class="wrap">
<view class="card-area">
<view class="top-description border-bottom">基礎(chǔ)用法</view>
<input class="ipt" placeholder="請(qǐng)?jiān)诖溯斎霕?biāo)題" />
</view>
</view>
代碼示例 2: 自定義輸入控制
<view class="wrap">
<view class="card-area">
<view class="top-description border-bottom">自定義輸入控制</view>
<view class="list-area border-bottom">
<view class="list-item-key-4">自動(dòng)聚焦</view>
<view class="list-item-value">
<input
placeholder='focus="true"'
selection-start="3"
selection-end="7"
focus="{{true}}"
confirm-hold="false"
confirm-type="send"
bindfocus="bindKeyfocus" />
</view>
</view>
<view class="list-area border-bottom">
<view class="list-item-key-4">控制長(zhǎng)度</view>
<view class="list-item-value">
<input
cursor="100"
bindblur="bindKeyblur"
bindconfirm="bindKeyconfirm"
placeholder='maxlength="10"'
maxlength="10" />
</view>
</view>
<view class="list-area border-bottom">
<view class="list-item-key-4">禁用</view>
<view class="list-item-value">
<input disabled="true" placeholder='disabled="true"' />
</view>
</view>
<view class="list-area">
<view class="list-item-key-4">帶有內(nèi)容</view>
<view class="list-item-value">
<input value='value="{= value =}"' />
</view>
</view>
</view>
</view>
Page({
data: {
inputValue: '',
autoFocus: true,
value: '初始value值'
},
onShow(){
this.setData({
autoFocus: true
});
},
bindButtonTap: function () {
this.setData({
focus: true
});
},
bindKeyInput: function (e) {
this.setData({
inputValue: e.detail.value
});
},
bindKeyfocus: function (e){
console.log(e.detail);
},
bindKeyblur: function (e){
swan.showToast({
title: '普通input失焦事件',
icon: 'none'
});
},
bindKeycomfirm: function (e){
swan.showToast({
title: '點(diǎn)擊確定',
icon: 'none'
});
}
});
代碼示例 3: 自定義輸入內(nèi)容
<view class="wrap">
<view class="card-area">
<view class="top-description border-bottom">自定義輸入內(nèi)容</view>
<view class="list-area border-bottom">
<view class="list-item-key-4">文本</view>
<view class="list-item-value">
<input
type="text"
placeholder='type="text"'
bindinput="{{!isWeb ? '': 'keyBoardText'}}"
value="{= textValue =}" />
</view>
</view>
<view class="list-area border-bottom">
<view class="list-item-key-4">數(shù)字</view>
<view class="list-item-value">
<input type="number" placeholder='type="number"' bindinput="{{!isWeb ? '': 'keyBoardNumber'}}" value="{= numberValue =}" />
</view>
</view>
<view class="list-area border-bottom">
<view class="list-item-key-4">身份證</view>
<view class="list-item-value">
<input type="idcard" adjust-position="true" placeholder='type="idcard"' bindinput="{{!isWeb ? '': 'keyBoardCard'}}" value="{= cardValue =}" />
</view>
</view>
<view class="list-area">
<view class="list-item-key-4">小數(shù)</view>
<view class="list-item-value">
<input type="digit" placeholder='type="digit"' bindinput="{{!isWeb ? '': 'keyBoardDigit'}}" value="{= digitValue =}" />
</view>
</view>
</view>
</view>
代碼示例 4: 自定義占位符顏色
<view class="wrap">
<view class="card-area">
<view class="top-description border-bottom">
<view>自定義占位符顏色</view>
<view>
placeholder-style=
color:"#3388FF"
</view>
</view>
<input class="ipt" placeholder-class="placeholder" placeholder-style="color:#3388FF" placeholder="請(qǐng)?jiān)诖溯斎? />
</view>
</view>
代碼示例 5: 實(shí)時(shí)獲取輸入值
<view class="wrap">
<view class="card-area">
<view class="top-description">
<view>實(shí)時(shí)獲取輸入值</view>
<view>bindinput="bindKeyInput"</view>
</view>
<view class="textarea">{{inputValue}}</view>
<input class="ipt" bindinput="bindKeyInput" placeholder="請(qǐng)?jiān)诖溯斎雰?nèi)容" />
</view>
</view>
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話(huà):173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: