简体   繁体   English

使用 fontawesome 的密码可见性图标

[英]Password visibility icon using fontawesome

I have this login form:我有这个登录表单:

<form class="form-signin" action="${postUrl ?: '/login/authenticate'}" method="POST" id="loginForm" autocomplete="off">
   <div class="form-group">
      <label for="username">Username</label>
      <input type="text" class="form-control" name="${usernameParameter ?: 'username'}" id="username" autocapitalize="none"/>
   </div>
   <div class="form-group">
      <label for="password">Password</label>
      <input type="password" class="form-control" name="${passwordParameter ?: 'password'}" id="password"/>
      <i id="passwordToggler" title="toggle password display" onclick="passwordDisplayToggle()"> &#128065</i>
   </div>
   <div class="form-group form-check">
      <label class="form-check-label">
         <input type="checkbox" class="form-check-input" name="${rememberMeParameter ?: 'remember-me'}" id="remember_me" 
         <g:if test='${hasCookie}'>checked="checked"</g:if>
         /> Remember me
      </label>
   </div>
   <button id="submit" class="btn btn-lg btn-primary btn-block text-uppercase" type="submit">Sign in</button>
</form>

Currently it using an eye emoji like this:目前它使用这样的眼睛表情符号: 在此处输入图像描述

But I want to change it to font awesome fa-eye also currently when I click on reveal password it showing cross sign and I also want to change that to eye lash icon as well.但是我现在也想将它更改为字体真棒fa-eye,当我点击显示密码时,它显示十字符号,我也想将其更改为睫毛图标。 Right now the eye and the cross sign icon I use unicode to display it.现在眼睛和十字符号图标我使用 unicode 来显示它。 Here is my javascript code:这是我的 javascript 代码:

 document.addEventListener("DOMContentLoaded", function(event) {
        document.forms['loginForm'].elements['username'].focus();
    });
    function passwordDisplayToggle() {
        var toggleEl = document.getElementById("passwordToggler");
        var eyeIcon = '\u{1F33D}';
        var xIcon = '\u{2715}';
        var passEl = document.getElementById("password");
        if (passEl.type === "password") {
            toggleEl.innerHTML = xIcon;
            passEl.type = "text";
        } else {
            toggleEl.innerHTML = eyeIcon;
            passEl.type = "password";
        }
    }

Any idea how I can switch it to font-awesome fa-eye?知道如何将其切换为字体真棒的 fa-eye 吗? Many thanks非常感谢

I have to replace it with this jquery code to make it work:我必须用这个 jquery 代码替换它才能使其工作:

    function passwordDisplayToggle() {

        var passEl = document.getElementById("password");
        var passToggler=$('#passwordToggler');

        if (passEl.type === "password") {
            passEl.type = "text";
            passToggler.removeClass('fa-eye');
            passToggler.addClass('fa-eye-slash');
        } else {
            passToggler.removeClass('fa-eye-slash');
            passToggler.addClass('fa-eye');
            // passToggler.addClass('d-none');
            passEl.type = "password";
        }
    }

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

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