简体   繁体   English

我该如何切换 <p:password> 带有复选框的文本和密码字段,请取消选中

[英]how can i toggle a <p:password> field to text and password with a checkbox check uncheck

I am using p:password tag for registration. 我正在使用p:password标签进行注册。 I want to toggle the field to text when it is checked with check box, it change to password type mode when it is unchecked. 我想在选中复选框时将字段切换为文本,当未选中时将其更改为密码类型模式。 How to solve the problem with primefaces component. 如何使用primefaces组件解决问题。 I am using primefaces 3.0 and jsf 2.0. 我正在使用primefaces 3.0和jsf 2.0。

under the cover generates the <input type="PASSWORD"/> field (with other attribute name etc..) 封面下将生成<input type="PASSWORD"/>字段(带有其他属性名称,等等。)

So now if you need to show password have a check box like 所以现在如果您需要显示密码,请选中一个复选框

<input type="checkbox" id="showPassword" onclick="showPassword()"/> Show password

in javascript 在JavaScript中

function showPassword(){
  var showPasswordCheckBox = document.getElementById("showPassword");
  if(showPasswordCheckBox.checked){
        document.getElementById("ID_FOR_YOUR_PASSWORD_FIELD").type="TEXT";
  }else{
      document.getElementById("ID_FOR_YOUR_PASSWORD_FIELD").type="PASSWORD";
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM