⼩程序input输⼊框详解及简单实例⼩程序输⼊框input
相关⽂章:
实现效果图:
⼩程序输⼊框input
属性名类型默认值说明
value String输⼊框的内容
type String text input的类型,有效值:text,number,idcard,digit,time,date password Boolean false是否是密码类型
placeholder String输⼊框为空时占位符
placeholder-
style
String指定placeholder的样式
placeholder-class String
input-
placeholder指定placeholder的样式类
disabled Boolean false是否禁⽤
maxlength Number140最⼤输⼊长度,设置为0的时候不限制最⼤长度
auto-focus Boolean false⾃动聚焦,拉起键盘。页⾯中只能有⼀个input设置auto-focus属性
focus Boolean false使得input获取焦点
bindchange EventHandle输⼊框失去焦点时,触发bindchange事件,event.detail={value:value} bindinput EventHandle除了date/time类型外的输⼊框,当键盘输⼊时,触发input事件,event.detail=
{value:value},处理函数可以直接return⼀个字符串,将替换输⼊框的内容。bindfocus EventHandle输⼊框聚焦时触发,event.detail = {value:value}
bindblur EventHandle输⼊框失去焦点时触发,event.detail = {value:value}
⽰例代码:
<!--input.wxml-->
<view class="section">
input标签placeholder属性
<input placeholder="这是⼀个可以⾃动聚焦的input" auto-focus/>
</view>
<view class="section">
<input placeholder="这个只有在按钮点击的时候才聚焦" focus="{{focus}}" />
<view class="btn-area">
<button bindtap="bindButtonTap">使得输⼊框获取焦点</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="连续的两个1会变成2" />
</view>
<view class="section">
<input bindinput="bindHideKeyboard" placeholder="输⼊123⾃动收起键盘" />
</view>
<view class="section">
<input type="emoji" placeholder="这是⼀个带有表情的输⼊框" />
</view>
<view class="section">
<input password type="number" />
</view>
<view class="section">
<input password type="text" />
</view>
<view class="section">
<input type="digit" placeholder="带⼩数点的数字键盘"/>
</view>
<view class="section">
<input type="idcard" placeholder="⾝份证输⼊键盘" />
</view>
<view class="section">
<input placeholder- placeholder="占位符字体是红⾊的" /> </view>
//input.js
Page({
data:{
focus:false,
inputValue:""
},
bindButtonTap:function(){
this.setData({
w()
})
},
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){
//光标在中间
var left = e.detail.value.slice(0,pos);
//计算光标的位置
pos = place(/11/g,'2').length;
}
/
/直接返回对象,可以对输⼊进⾏过滤处理,同时可以控制光标的位置
return {
place(/11/g,'2'),
cursor:pos
}
//或者直接返回字符串,光标在最后边
//place(/11/g,'2'),
},
bindHideKeyboard:function(e){
if(e.detail.value === "123"){
//收起键盘
wx.hideKeyboard();
}
}
})
感谢阅读,希望能帮助到⼤家,谢谢⼤家对本站的⽀持!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。