温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

微信小程序怎么实现输入支付密码demo

发布时间:2022-03-11 10:59:46 阅读:196 作者:iii 栏目:开发技术
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

这篇文章主要介绍了微信小程序怎么实现输入支付密码demo 的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇微信小程序怎么实现输入支付密码demo 文章都会有所收获,下面我们一起来看看吧。

微信小程序怎么实现输入支付密码demo

微信小程序开发实现微信支付密码的输入,要解决:

1、小程序要想唤起键盘,必须要借助input控件。通过input控件和其属性focus来唤起和隐藏输入键盘。

2、要让input控件不可见。让光标和输入的字符都不可见,这里是把input控件定位到左边不可见范围。

实现demo代码:

1、页面代码

<view catchtap='showInputLayer' class="btn_pay">立即支付</view><!-- 密码输入框 --><view wx:if='{{showPayPwdInput}}'><view class='bg_layer'></view><view class='input_main'><view class='input_title'><view class='input_back' catchtap='hidePayLayer'><text></text></view><text>输入支付密码</text></view><view class='input_tip'><text>使用会员卡余额支付需要验证身份,验证通过后才可进行支付。</text></view><view class='input_row' catchtap='getFocus'><view class='pwd_item' wx:for='{{6}}' wx:key='item' wx:for-index='i'><text wx:if='{{pwdVal.length>i}}'></text></view></view><view class='forget_pwd' catchtap='hidePayLayer'>忘记密码</view><input class='input_control' password type='number' focus='{{payFocus}}' bindinput='inputPwd' maxlength='6'/></view></view>

2、js代码

//index.js//获取应用实例const app = getApp() Page({data: {showPayPwdInput: false, //是否展示密码输入层pwdVal: '', //输入的密码payFocus: true, //文本框焦点},onLoad: function () {this.showInputLayer();},/*** 显示支付密码输入层*/showInputLayer: function(){this.setData({ showPayPwdInput: true, payFocus: true });},/*** 隐藏支付密码输入层*/hidePayLayer: function(){ var val = this.data.pwdVal; this.setData({ showPayPwdInput: false, payFocus: false, pwdVal: '' }, function(){wx.showToast({title: val,})}); },/*** 获取焦点*/getFocus: function(){this.setData({ payFocus: true });},/*** 输入密码监听*/inputPwd: function(e){this.setData({ pwdVal: e.detail.value }); if (e.detail.value.length >= 6){this.hidePayLayer();}}})

3、样式

.btn_pay{margin100rpx auto; width600rpx; height100rpx; line-height100rpx; border-radius100rpx;background-color#d3a95acolor#ffffont-size36rpx; text-align: center;}/* 支付密码css start */.bg_layer{position: fixed; left0top0bottom0right0;background-colorrgba(0000.6); z-index9998;}.input_main{position: fixed; left0bottom500rpx; width100%height394rpx;background-color#fffz-index9999;}.input_title{width100%height90rpx; line-height90rpx; text-align: center;font-size32rpx; border-bottom1rpx solid #e2e2e2;}.input_back{position: absolute; left0top0;width80rpx; height90rpx; display: flex; justify-content: center; align-items: center;}.input_back text{width20rpx;height20rpx;background-color: white;border1rpx solid #aaa;border-width5rpx 0 0 5rpx;transformrotate(-45deg);} .input_tipmargin30rpx; font-size24rpx; color#888; } /* 密码掩码模拟 */.input_row{width690rpx; margin0 auto; height98rpx; position: relative;display: flex; align-items: center; border1rpx solid #e2e2e2border-radius20rpx;}.input_row .pwd_item{flex1display: flex; align-items: center; justify-content: center;height100%border-right1rpx solid #e2e2e2position: relative;}.pwd_item:nth-last-of-type(1) { border-right0; }.pwd_item text {width30rpx; height30rpx; border-radius30rpx; background-color#555;}  .forget_pwd{float: right; margin30rpx; width100rpx; text-align: right; font-size24rpx; color#ff7800;} /* 文本输入框位置: 设置到左边隐藏 */.input_control {position: relative; left: -300rpx; bottom0width100rpx; height100rpx;}

关于“微信小程序怎么实现输入支付密码demo ”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“微信小程序怎么实现输入支付密码demo ”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×