JS achieve password login page is displayed and hidden features

In the login page are often used to implement the functionality hide password displayed by clicking on the text box similar picture small eyes, in fact achieve the principle is very simple, to change the input type by clicking the type of event, the specific process of looking at the code:

Before did not realize to share code would let you display the next renderings:

JS achieve password login page is displayed and hidden features

JS achieve password login page is displayed and hidden features

<ul class="form-area">
 <li>
  <div class="item-content">
   <div class="item-input">
    <input type="text" name="accountName" autofocus required="required" placeholder="请输入用户名">
   </div>
  </div>
 </li>
 <li>
  <div class="item-content">
   <div class="item-input">
     <input type="password" name="password" id="password" required="required" placeholder="请输入密码">
   </div>
  </div>
 </li>
 <li>
  <span style="position:absolute;right: 20px;top: -38px">
   <img id="showText" onclick="hideShowPsw()">
  </span>
 </li>
</ul>
<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>

to sum up

JS achieve the above is a login page password small series to introduce and hidden, we want to help, if you have any questions please give me a message, Xiao Bian will promptly reply to everyone. Here also very grateful to everyone for their support of our site!

Guess you like

Origin www.cnblogs.com/lsongyang/p/11915434.html