js input Password box prompt message of html5 implementation method

  • 2020-12-05 17:07:07
  • OfStack

An example of js to implement input password box prompts the method. To share for your reference, the details are as follows:

Today, our supervisor said that we would add a "please enter password" prompt message in the password box. The first time, I was thinking of modifying the input type attribute, but some special browsers did not support it. The type attribute of input of IE is read-only and cannot be set dynamically. So in other ways, examples are as follows:


<input type="text" onfocus="changeTip(this);" id="passText" name="passText" value=" Please enter your password. "/>
<input style="display: none;" type="password" onblur="changeTip(this);" id="pass" placeholder="" name="pass" value=""/>
<script type="text/javascript">
function changeTip(th){
 var passText = document.getElementById('passText');
 var pass = document.getElementById('pass');
 if(th.id == 'pass'){
  if(th.value == '' || th.value.length == 0 ){
   passText.style.display='';
   pass.style.display='none';
  }
 }else{
  passText.style.display='none';
  pass.style.display='';
  pass.focus();
 }
}
</script>

Supplement:

In fact, the above 1 block of code, using html5 1 placeholder attribute to solve. The code is as follows:

<input type="password" id="pass5" placeholder=" Please enter your password. " name="pass5" value=""/>

PS: Here is a very good JavaScript compression, formatting and encryption tools, very powerful (for those who want to code encryption friends might as well try js encryption function here) :

JavaScript compression/formatting/encryption tools: http: / / tools ofstack. com/code/jscompress

In addition, the above js tool encryption is used in eval function encryption form, this site also provides the following for eval function encryption decryption tools, very powerful and practical!

js eval method online encryption decryption tool: http: / / tools ofstack. com/password/evalencode

I hope this article has helped you with the JavaScript programming.


Related articles: