Home > Web Front-end > JS Tutorial > body text

How to display and hide the login page password in JS

亚连
Release: 2018-06-22 14:38:24
Original
3666 people have browsed it

On the login page, the function of hiding and displaying the password is often used by clicking on the small eye-like picture in the text box. Let me introduce to you how to display and hide the password on the login page based on JS. Friends who need it can refer to it

On the login page, it is often used to hide and display the password by clicking on a small eye-like picture in the text box. Function, in fact, the implementation principle is very simple. The input type is changed through the click event. The specific process is shown in the code:

Before I share the implementation code with you, let me show you the rendering:

How to display and hide the login page password in JS

How to display and hide the login page password in JS

<ul class="form-area">
 <li>
  <p class="item-content">
   <p class="item-input">
    <input type="text" name="accountName" autofocus required="required" placeholder="请输入用户名">
   </p>
  </p>
 </li>
 <li>
  <p class="item-content">
   <p class="item-input">
     <input type="password" name="password" id="password" required="required" placeholder="请输入密码">
   </p>
  </p>
 </li>
 <li>
  <span style="position:absolute;right: 20px;top: -38px">
   <img  id="showText" onclick="hideShowPsw()" alt="How to display and hide the login page password in JS" >
  </span>
 </li>
</ul>
Copy after login
<script type="text/javascript">
//获取input框内的切换图片id和input文本框的id
 var demoImg = document.getElementById("showText");
 var demoInput = document.getElementById("password");
 function hideShowPsw() {
  if (demoInput.type == "password") {
   demoInput.type = "text";
   demoImg.src ="../Images/showPasswd.png";
  } else {
   demoInput.type = "password";
   demoImg.src = "../Images/hidePasswd.png";
  }
 }
</script>
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

What should you pay attention to when optimizing Vue projects?

Developed in a modular way in vuejs

How to implement the array update function in VUE

How to use vue-cli to implement multi-page applications

The above is the detailed content of How to display and hide the login page password in JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!