小编ban*_*nto的帖子

在 Keycloak 的密码字段中显示/隐藏密码切换

我已经编辑了 script.js 的代码,用于在 Keycloak 的密码字段中显示/隐藏密码切换,但它不起作用。请查看它并告诉我,我怎样才能使它工作?谢谢

在script.js中添加:

// Rudimentary method for adding a password reveal button.
window.onload = function() {
  var fToggle = function($password, e) {
    e.preventDefault();
    const type = $password.getAttribute('type') === 'password' ? 'text' : 'password';
    $password.setAttribute('type', type);
    this.classList.toggle('bi-eye');
  };

  var createReveal = function(passwordId, toggleId) {
    var password = document.getElementById(passwordId);
    if ((password) && (password.style) && (password.style.display !== 'none')){
      var icon = document.createElement("i");
      icon.id = toggleId;
      icon.classList.add('password-reveal', 'bi', 'bi-eye-slash');
      icon.addEventListener('click', fToggle.bind(icon, password)); 
      password.parentNode.insertBefore(icon, password.nextSibling);
    }
  };

  createReveal('password', 'togglePassword');
  createReveal('password-new', 'togglePasswordNew'); …
Run Code Online (Sandbox Code Playgroud)

keycloak

4
推荐指数
1
解决办法
2655
查看次数

标签 统计

keycloak ×1