input组件动态设置type不生效?
发布于 4 年前 作者 ogong 4730 次浏览 来自 问答

 <input type="{{show}}"  value='{{password}}' bindinput='getPassWordplaceholder="请输入密码placeholder-class="input-placeholder"></input>

   <image class="psdMagebindtap="showPassword"  src="/pages/img/showPassword.png"></image>

 data: {

    isShow: false,   

    show:"text"   

  },


  showPassword: function() {

    if (this.data.isShow{   

        this.setData({

          isShow:false,

          show:"password"

        })

    } else {

      this.setData({

        isShow: true,

        show: "text"

      })

    }

  },

1 回复
<input type="text" value='{{password}}' bindinput='getPassWord' placeholder="请输入密码" placeholder-class="input-placeholder"wx:if="{{show}}" />
<input type="password" value='{{password}}' bindinput='getPassWord' placeholder="请输入密码" placeholder-class="input-placeholder"wx:if="{{!show}}" />
// 老毛病了,可以通过以上方式规避。如果是点击眼睛切换后需要聚焦input,再加上 focus 属性
回到顶部