在微信小程序里,实现点击框里的眼睛图标时密码显示与隐藏切换

大家自己脑补一下,就是当你输入QQ密码时的一些展示和操作
具体看代码,亲测真机模拟有效(具体看GIF)
还有还有,一开始想的用type,但网上都说真机不成功,所以也就不试了,下面这种方法也是借鉴CSDN上的大佬。跪谢!!!
分享给有需要的朋友们

在这里插入图片描述
wxml

<view class='parentstyle '>
    <view class='centerStyle'>
      <input password='{{passwordType}}' maxlength="20" placeholder="请输入密码" style='font-size:34rpx'></input>
      <image src='{{defaultType? "../../assets/closeye.png": "../../assets/openeye.png"}}' class='imageStyle' bindtap='eyeStatus'></image>
    </view>
</view>

wxss

.parentstyle {
  display: flex;
  align-items: center;
  border: 1rpx solid #e0e0e0;
  border-radius: 10rpx;
  box-shadow: 0 0 5rpx #e0e0e0;
  margin: 30rpx 38px;
  padding: 20rpx;
}

.parentstyle .imageStyle {
  width: 41rpx;
  height: 41rpx;
  margin-right: 20rpx;
}

.parentstyle .centerStyle {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  font-size: 28rpx;
}

js

Page({
  data: {
    defaultType: true,
    passwordType: true
  },
  //defaultType:眼睛状态   passwordType:密码可见与否状态
  eyeStatus: function(){
    this.data.defaultType= !this.data.defaultType
    this.data.passwordType= !this.data.passwordType
    this.setData({
      defaultType: this.data.defaultType,
      passwordType: this.data.passwordType
  })

  }

})

  • 6
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值