Home > Web Front-end > JS Tutorial > How to implement input password box prompt information in js (with html5 implementation method)_javascript skills

How to implement input password box prompt information in js (with html5 implementation method)_javascript skills

WBOY
Release: 2016-05-16 15:20:04
Original
1325 people have browsed it

The example in this article describes how to implement input password box prompt information in js. Share it with everyone for your reference, the details are as follows:

Today our supervisor said that we should add a "please enter password" prompt message in the password box. The first time we thought about using the method of modifying the input type attribute, it turned out that some special browsers did not support it, IE The type attribute of the input is read-only and cannot be set dynamically. So use other methods. The example is as follows:

<input type="text" onfocus="changeTip(this);" id="passText" name="passText" value="请输入密码"/>
<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>
Copy after login

Supplement:

In fact, the above large section of code can be solved using a placeholder attribute of HTML5. The code is as follows:

Copy code The code is as follows:

PS: Here we recommend a very easy-to-use JavaScript compression, formatting and encryption tool, which is very powerful (for those who want to encrypt their code, you may want to try it Try the js encryption function here):

JavaScript compression/formatting/encryption tool: http://tools.jb51.net/code/jscompress

In addition, the encryption in the above js tool uses the eval function encryption form. For this purpose, this site also provides the following decryption tool for eval function encryption, which is very powerful and practical!

JS eval method online encryption and decryption tool: http://tools.jb51.net/password/evalencode

I hope this article will be helpful to everyone in JavaScript programming.

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