ITPub博客

首页 > IT职业 > IT职场 > js实现密码框的点击眼睛的显示与隐藏

js实现密码框的点击眼睛的显示与隐藏

IT职场 作者:mahaijiang 时间:2021-09-09 10:08:11 0 删除 编辑

密码框的点击眼睛的显示与隐藏,图标引用是bootstrap中的fontawesome(复制整个 font-awesome 文件夹到您的项目中)还需要引入  <link rel="stylesheet" type="text/css" href="bootstrap.min.css">  <link rel="stylesheet" type="text/css" href="Font-Awesome/css/font-awesome.min.css"><!doctype html><html>    <head>            <meta charset="utf-8">            <title>密码框</title>            <link rel="stylesheet" type="text/css" href="bootstrap.min.css">            <link rel="stylesheet" type="text/css" href="Font-Awesome/css/font-awesome.min.css">    </head><body>    <div class="content">        <div class="input_block">            <i class="fa fa-eye" onclick="hideShowPsw()" id="eye"></i>            <input type="password" id="password" placeholder="密码"/>        </div>    </div>   <script type="text/javascript">            var eye = document.getElementById("eye");            var password = document.getElementById("password");            //隐藏text block,显示password block            function hideShowPsw(){                    if (password.type == "password") {                            password.type = "text";                            eye.className='fa fa-eye-slash'                    }else {                            password.type = "password";                            eye.className='fa fa-eye'                    }                }    </script></body></html>

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3071/viewspace-2817159/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-13

  • 博文量
    76
  • 访问量
    779