Implement Password box default text effect instance code

Source: Internet
Author: User

Implement Password box default text effect instance code:
We all know that many text boxes have default prompt text by default, such as "Please enter name" Language, when you click on the text box, will clear the prompt, more humane. But it might be a little tricky to do this in the Password box, because the password box is not shown in clear text, so here's an example of a code instance that solves the problem.
The code is as follows:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.softwhy.com/" /><title>Ant Tribe</title><Scripttype= "Text/javascript">window.onload=function(){  varTX=document.getElementById ("TX"); varpwd=document.getElementById ("pwd"); Tx.onfocus=function()  {     if( This. Value!="Please enter your password") return;  This. Style.display="None"; Pwd.style.display=""; Pwd.value="";   Pwd.focus (); } Pwd.onblur=function()  {     if( This. Value!="") return;  This. Style.display="None"; Tx.style.display=""; Tx.value="Please enter your password"; }  }</Script></Head><Body><inputtype= "text"value= "Please enter password"ID= "TX"style= "width:100px;" /><inputtype= "Password"ID= "pwd"style= "display:none;width:100px;"  /></Body></HTML>

The above code to achieve our needs, the default state has a clear text prompt, after the click can enter the password, the following describes the process of dimly realized.
I. Principle of implementation:
In fact, the principle is very simple, in the default display of a text box, the Password box is set to invisible state, when the text box is clicked, the text box is set to invisible, the real password box shows the position of the replacement text box, so that the effect is achieved.
Two. Related reading:
The 1.onfocus event can be found in the Onfocus event section of JavaScript .
The 2.focus () function can be found in the Text.focus () method section of JavaScript .
The 3.onblur event can be found in the Onblur event section of JavaScript .
4.value properties can be found in the Text.value Properties section of JavaScript .

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=9525

For more information, refer to: http://www.softwhy.com/javascript/

Implement Password box default text effect instance code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.