how to make password textbox value visible when hover an icon

前端 未结 11 1101
误落风尘
误落风尘 2021-01-31 03:01

Good day all,

I have a form that has a password field:


Naturally, the i

11条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 03:42

    Complete example below. I just love the copy/paste :)

    HTML

    CSS

    .field-icon {
      float: right;
      margin-right: 8px;
      margin-top: -23px;
      position: relative;
      z-index: 2;
      cursor:pointer;
    }
    
    .container{
      padding-top:50px;
      margin: auto;
    }
    

    JS

    $(".toggle-password").click(function() {
       $(this).toggleClass("fa-eye fa-eye-slash");
       var input = $($(this).attr("toggle"));
       if (input.attr("type") == "password") {
         input.attr("type", "text");
       } else {
         input.attr("type", "password");
       }
    });
    

    Try it here: https://codepen.io/anon/pen/ZoMQZP

提交回复
热议问题