惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
GbyAI
GbyAI
P
Proofpoint News Feed
Microsoft Security Blog
Microsoft Security Blog
月光博客
月光博客
I
InfoQ
V
Visual Studio Blog
罗磊的独立博客
Engineering at Meta
Engineering at Meta
Vercel News
Vercel News
Jina AI
Jina AI
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
The Cloudflare Blog
小众软件
小众软件
雷峰网
雷峰网
V
V2EX
人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog

博客园 - ZhuQue

软件测试报告在高新技术企业(高企)认定报告中具有重要作用 windows下监控mongoDB数据库 软件测试中如何进行全面测试 什么是性能测试服务,以及进行哪些测试? 软件测试报告与测试计划的关系探讨 软件测试报告中的关键指标解读 软件测试报告这样写,项目结题一路绿灯! 软件项目产品质量验收标准及验收方法 什么情况下软件测试报告使用CNAS/CMA标识?哪种情况软件测试报告要加盖CMA印章 XMind2020思维导图软件下载地址 网站后台SMTP协议发送邮件,提示“SMTP Error: Could not connect to SMTP host。” python3.4版本32位环境安装pyinstaller 中标麒麟3.2版本对应RedHat linux 6版本 多线程上下文切换与高并发 对k8s中pod的理解 InfluxDB数据库管理工具InfluxDBStudio使用 eclipse代码中添加图片后页面不显示图片,提示“Whitelabel Error Page” maven项目中@Override的问题,提示“[51,17] 方法不会覆盖或实现超类型的方法‘ centos系统systemctl restart network启动失败,提示“code=exited status=1”
给登录模块添加密码明文、密文切换功能(即睁眼、闭眼功能)
ZhuQue · 2021-02-17 · via 博客园 - ZhuQue

我做的这个测试系统所属的功能模块用的是默认自带的,没有密码明文、密文显示功能,也就是我们在登录时经常使用的,默认显示输入的密文,点击“睁眼”图片显示明文,点击“闭眼”图片显示密文。

                              

以下三段代码放到login.html页面中即可:包括CSS样式代码、JS实现代码、password调用代码,其中css和js代码可以分开放到不同的文件中也是可以的。

1、CSS样式代码,放到<head></head>中:

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>测试管理系统</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" href="css/bootstrap.min.css">
  <link rel="stylesheet" href="css/font-awesome.min.css">
  <link rel="stylesheet" href="css/AdminLTE.min.css">

  <style type="text/css">
    #img {
        width: 25px;
        height: 25px;
        position: absolute;
        right: 10px;
        margin-top: 12px;
        top: 5px;
        text-align: center;
    }
</style>
</head>

2、JS实现代码,放到<body></body>中任何位置(我是放到了login.html页面的最下头):

<body>

。。。。
。。。。


<script type="text/javascript">
      //添加登录密码明文、密文切换功能20210216
      var demoImg = document.getElementById("img");
      var PWD = document.getElementById("HXB-login-password");
   
      function hideShowPsw() {
          if (PWD.type == "password") {
              PWD.type = "text";
              demoImg.src = "/swagger/images/icon-invisible.png"; //闭眼图片
          } else {
              PWD.type = "password";
              demoImg.src = "/swagger/images/icon-visible.png"; // 睁眼图片
          }
      }     
</script>
</body>

3、登录代码中password调用代码

代码中 id="HXB-login-password" 和 onclick="hideShowPsw()" 就是调用的js的方法,名称可以自定义修改。

  <div class="login-box-body">
      
      <div v-if="error" class="alert alert-danger alert-dismissible">
        <h4 style="margin-bottom: 0px;"><i class="fa fa-exclamation-circle"></i> {{errorMsg}}</h4>
      </div>
      <div class="form-group has-feedback">
          登录账号代码 
      </div>
     
     <div class="form-group has-feedback">
           <input id="HXB-login-password" type="password" class="form-control-login" v-model="form.password" placeholder="密码" >
           <img id="img" onclick="hideShowPsw()" src="/swagger/images/icon-visible.png">
      </div>
      
      <div class="form-group has-feedback">
          验证码代码 
      </div>
      <div class="form-group has-feedback">
          刷新验证码代码
      </div>

      <div class="row">
        <!-- /.col -->
        <div class="col-xs-4">
          <button type="button" class="btn btn-primary-login btn-block btn-flat" @click="login">登录</button>
        </div>
        <!-- /.col -->
      </div>

用到的睁眼图片、闭眼图片,自己下载:

睁眼图片:https://www.iconfont.cn/search/index?searchType=icon&q=%E7%9D%81%E7%9C%BC

闭眼图片:https://www.iconfont.cn/search/index?searchType=icon&q=%E9%97%AD%E7%9C%BC

图片下载后放到网站images目录中。

我用的eclipse,还需要点击项目名称F5刷新以下才可以。