微信小程序验证码/密码输入框,一个框一个数字

wxml:

<form bindsubmit="formSubmit">  
  
  <view class='content'>  
  
    <block wx:for="{{Length}}" wx:key="item">  
      <input class='iptbox' value="{{Value.length>=index+1?Value[index]:''}}" disabled password='{{ispassword}}' catchtap='Tap'></input>  
    </block>  
  
  </view>  
  
  <input name="password" password="{{true}}" class='ipt' maxlength="{{Length}}" focus="{{isFocus}}" bindinput="Focus"></input>  
  
  <view>  
    <button class="btn-area" formType="submit">Submit</button>  
  </view>  
  
</form>  


js:

Page({  
  
  /** 
   * 页面的初始数据 
   */  
  data: {  
    Length:6,        //输入框个数  
    isFocus:true,    //聚焦  
    Value:"",        //输入的内容  
    ispassword:true, //是否密文显示 true为密文, false为明文。  
  },  
  Focus(e){  
    var that = this;  
    console.log(e.detail.value);  
    var inputValue = e.detail.value;  
    that.setData({  
      Value:inputValue,  
    })  
  },  
  Tap(){  
    var that = this;  
    that.setData({  
      isFocus:true,  
    })  
  },  
  formSubmit(e){  
    console.log(e.detail.value.password);  
  },  
})  




wxss:

content{  
  display: flex;  
  justify-content: space-around;  
  align-items: center;  
  margin-top: 200rpx;  
}  
.iptbox{  
  width: 80rpx;  
  height: 80rpx;  
  border:1rpx solid #ddd;  
  border-radius: 20rpx;  
  display: flex;  
  justify-content: center;  
  align-items: center;  
  text-align: center;  
}  
.ipt{  
  width: 0;  
  height: 0;  
}  
.btn-area{  
  width: 80%;  
  background-color: orange;  
  color:white;  
}  

思路:
1、放置一个输入框,隐藏其文字和位置,同时设置支付输入框(表格)样式
2、当点击输入框时设置输入框为聚焦状态,唤起键盘,点击空白处,失去焦点,设为失去焦点样式,因为输入框宽高为0,所以不会显示输入框和光标,实现隐藏。
3、限制输入框最大字数并且监听输入框状态,以输入框值的长度作为输入框(表格)内容的渲染条件
4、点击提交按钮时,获取输入框内容。


转自:https://blog.csdn.net/weixin_41871290/article/details/80512600

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值