微信小程序想要再下一个输入框输入时,必须先点击屏幕收起键盘再点击下一个输入框唤起键盘,有没有什么丝滑的方法?教教我!谢谢!
在全局变量修改
使用获取焦点的方式试试看。
例:
Page({
data: {
formInputItems: [
{
type: 'text',
password: false,
placeholder: '请输入账号',
focus: false,
value: ''
},
{
type: 'text',
password: false,
placeholder: '请输入手机号',
focus: false,
value: ''
},
{
type: 'text',
password: false,
placeholder: '请输入性别',
focus: false,
value: ''
},
{
type: 'text',
password: false,
placeholder: '请输入爱好',
focus: false,
value: ''
}
]
},
onLoad() {
},
onConfirm(e) {
const index = e.currentTarget.dataset.index;
if (index < this.data.formInputItems.length - 1) {
this.setData({
[`formInputItems[${index}].focus`]: false,
[`formInputItems[${index + 1}].focus`]: true
})
}else{
console.log(this.data.formInputItems);
}
},
onInput(e) {
const index = e.currentTarget.dataset.index;
this.setData({
[`formInputItems[${index}].value`]: e.detail.value
})
}
})
index.wxml
<view class="form-item" wx:for="{{formInputItems}}" wx:key="unique">
<input type="{{item.type}}" password="{{item.password}}" placeholder="{{item.placeholder}}" focus="{{item.focus}}" confirm-type="{{index==formInputItems.length-1?'done':'next'}}" bindconfirm="onConfirm" bindinput="onInput" data-index="{{index}}" />
</view>