小程序密码输入框

10 篇文章 0 订阅

小程序密码输入框

wxml

<view class="Toptitle">请设置支付密码并妥善保管</view>
<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" type='primary' disabled='{{disabled}}' formType="primary">下一步</button>
  </view>
</form>

wxss

/* pages/mima/mima.wxss */
.Toptitle{
  text-align: center;
  margin: 60rpx auto 46rpx;
  font-size: 26rpx;
}
.content{
  width: 660rpx;
  padding:0 45rpx;
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin-top: 100rpx;
}
.iptbox{
  width: 110rpx;
  height: 96rpx;
  border:1rpx solid #ddd;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.ipt{
  width: 0;
  height: 0;
}
.btn-area{
  width: 80%;
  margin-top: 60rpx;
}

js

 
Page({
  data: {
    Length: 6,        //输入框个数
    isFocus: true,    //聚焦
    Value: "",        //输入的内容
    ispassword: true, //是否密文显示 true为密文, false为明文。
    disabled:true,
  },
  Focus(e) {
    var that = this;
    console.log(e.detail.value);
    var inputValue = e.detail.value;
    var ilen = inputValue.length;
    if(ilen == 6){
      that.setData({
        disabled: false,
      })
    }else{
      that.setData({
        disabled: true,
      })
    }
    that.setData({
      Value: inputValue,
    })
  },
  Tap() {
    var that = this;
    that.setData({
      isFocus: true,
    })
  },
  formSubmit(e) {
    console.log(e.detail.value.password);
  },
 
  onLoad: function (options) {
  
  },
  onShow: function () {
  
  },
})

以上仅供参考,主要方便自己学习!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值