微信小程序 input輸入框詳解及簡單實(shí)例
更新時(shí)間:2017年01月10日 14:47:48 投稿:lqh
這篇文章主要介紹了微信小程序 input輸入框詳解及簡單實(shí)例的相關(guān)資料,需要的朋友可以參考下
微信小程序輸入框input
相關(guān)文章:
實(shí)現(xiàn)效果圖:
微信小程序輸入框input
| 屬性名 | 類型 | 默認(rèn)值 | 說明 |
|---|---|---|---|
| value | String | 輸入框的內(nèi)容 | |
| type | String | text | input的類型,有效值:text,number,idcard,digit,time,date |
| password | Boolean | false | 是否是密碼類型 |
| placeholder | String | 輸入框?yàn)榭諘r(shí)占位符 | |
| placeholder-style | String | 指定placeholder的樣式 | |
| placeholder-class | String | input-placeholder | 指定placeholder的樣式類 |
| disabled | Boolean | false | 是否禁用 |
| maxlength | Number | 140 | 最大輸入長度,設(shè)置為0的時(shí)候不限制最大長度 |
| auto-focus | Boolean | false | 自動(dòng)聚焦,拉起鍵盤。頁面中只能有一個(gè)input設(shè)置auto-focus屬性 |
| focus | Boolean | false | 使得input獲取焦點(diǎn) |
| bindchange | EventHandle | 輸入框失去焦點(diǎn)時(shí),觸發(fā)bindchange事件,event.detail={value:value} | |
| bindinput | EventHandle | 除了date/time類型外的輸入框,當(dāng)鍵盤輸入時(shí),觸發(fā)input事件,event.detail={value:value},處理函數(shù)可以直接return一個(gè)字符串,將替換輸入框的內(nèi)容。 | |
| bindfocus | EventHandle | 輸入框聚焦時(shí)觸發(fā),event.detail = {value:value} | |
| bindblur | EventHandle | 輸入框失去焦點(diǎn)時(shí)觸發(fā),event.detail = {value:value} |
示例代碼:
<!--input.wxml-->
<view class="section">
<input placeholder="這是一個(gè)可以自動(dòng)聚焦的input" auto-focus/>
</view>
<view class="section">
<input placeholder="這個(gè)只有在按鈕點(diǎn)擊的時(shí)候才聚焦" focus="{{focus}}" />
<view class="btn-area">
<button bindtap="bindButtonTap">使得輸入框獲取焦點(diǎn)</button>
</view>
</view>
<view class="section">
<input maxlength="10" placeholder="最大輸入長度10" />
</view>
<view class="section">
<view class="section__title">你輸入的是:{{inputValue}}</view>
<input bindinput="bindKeyInput" placeholder="輸入同步到view中"/>
</view>
<view class="section">
<input bindinput="bindReplaceInput" placeholder="連續(xù)的兩個(gè)1會(huì)變成2" />
</view>
<view class="section">
<input bindinput="bindHideKeyboard" placeholder="輸入123自動(dòng)收起鍵盤" />
</view>
<view class="section">
<input type="emoji" placeholder="這是一個(gè)帶有表情的輸入框" />
</view>
<view class="section">
<input password type="number" />
</view>
<view class="section">
<input password type="text" />
</view>
<view class="section">
<input type="digit" placeholder="帶小數(shù)點(diǎn)的數(shù)字鍵盤"/>
</view>
<view class="section">
<input type="idcard" placeholder="身份證輸入鍵盤" />
</view>
<view class="section">
<input placeholder-style="color:red" placeholder="占位符字體是紅色的" />
</view>
//input.js
Page({
data:{
focus:false,
inputValue:""
},
bindButtonTap:function(){
this.setData({
focus:Date.now()
})
},
bindKeyInput:function(e){
this.setData({
inputValue:e.detail.value
})
},
bindReplaceInput:function(e){
var value = e.detail.value;
var pos = e.detail.cursor;
if(pos != -1){
//光標(biāo)在中間
var left = e.detail.value.slice(0,pos);
//計(jì)算光標(biāo)的位置
pos = left.replace(/11/g,'2').length;
}
//直接返回對(duì)象,可以對(duì)輸入進(jìn)行過濾處理,同時(shí)可以控制光標(biāo)的位置
return {
value:value.replace(/11/g,'2'),
cursor:pos
}
//或者直接返回字符串,光標(biāo)在最后邊
//return value.replace(/11/g,'2'),
},
bindHideKeyboard:function(e){
if(e.detail.value === "123"){
//收起鍵盤
wx.hideKeyboard();
}
}
})
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
微信小程序?qū)崿F(xiàn)多個(gè)按鈕toggle功能的實(shí)例
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)多個(gè)按鈕toggle功能的實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-06-06
微信小程序 網(wǎng)絡(luò)API Websocket詳解
這篇文章主要介紹了微信小程序 網(wǎng)絡(luò)API Websocket詳解的相關(guān)資料,需要的朋友可以參考下2016-11-11
微信小程序 本地?cái)?shù)據(jù)讀取實(shí)例
這篇文章主要介紹了微信小程序 本地?cái)?shù)據(jù)讀取實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-04-04
electron創(chuàng)建新窗口模態(tài)框并實(shí)現(xiàn)主進(jìn)程傳值給子進(jìn)程
這篇文章主要為大家介紹了electron創(chuàng)建新窗口模態(tài)框并實(shí)現(xiàn)主進(jìn)程傳值給子進(jìn)程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
微信小程序手勢操作之單觸摸點(diǎn)與多觸摸點(diǎn)
這篇文章主要介紹了微信小程序手勢操作之單觸摸點(diǎn)與多觸摸點(diǎn)的相關(guān)資料,需要的朋友可以參考下2017-03-03
javascript實(shí)現(xiàn)超炫的向上滑行菜單實(shí)例
這篇文章主要介紹了javascript實(shí)現(xiàn)超炫的向上滑行菜單實(shí)現(xiàn)方法,以一個(gè)完整實(shí)例形式分析了javascript針對(duì)頁面元素的遍歷與樣式操作相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08
'2'>'10'==true?解析JS如何進(jìn)行隱式類型轉(zhuǎn)換
這篇文章主要為大家介紹了'2'>'10'==true?解析JS如何進(jìn)行隱式類型轉(zhuǎn)換示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09


