3 回复
< view > < view class = "bind-content" > < block wx:for = "{{ inputLength }}" wx:key = "index" > < input class = "bind-box__item" type = "number" value="{{ inputVal.length >= index + 1 ? inputVal[index] : '' }}" disabled catchtap="getFocus"></ input > </ block > </ view > < input name = "password" type = "number" class = "bind-box__cnt" maxlength = "{{ inputLength }}" focus = "{{ isFocus }}" bindinput = "handleInput" ></ input > </ view > |
.bind-content { display : flex; justify- content : space-around; align-items: center ; margin-top : 70 rpx; margin-left : 20px ; margin-right : 20px ; } .bind-box__item { width : 60 rpx; height : 80 rpx; font-size : 24px ; font-weight : bold ; border-bottom : 4 rpx solid #ddd ; display : flex; justify- content : center ; align-items: center ; text-align : center ; } .bind-box__cnt { width : 0 ; height : 0 ; } |
data: { inputLength: 6, isFocus: true , inputVal: '' }, handleInput(e) { let that = this , val = e.detail.value; that.setData({ inputVal: val, })
} }, getFocus() { var that = this ; that.setData({ isFocus: true , }) } |
不需要6个input,只需要一个正常输入的input,然后通过输入的长度,逐个重新渲染在其他view上就可以了。输入和展示分开的逻辑