Login event, mouse click on the input box to hide the default value event

Source: Internet
Author: User

Css:

1 <style> 2     #txt1, #txt2{ color:#CCC; border:1px solid #666;} 3     #pswd{ display:none;  Border:1px solid #666;} 4 </style>        

Reference JS Library:

1 <script src= "Http://libs.baidu.com/jquery/1.7.2/jquery.min.js" ></script>

Html:

1 <formID= "MyForm"Action="#">2 Address:3     <inputtype= "text"ID= "Txt1"value= "Please enter your email address" />4 5     <BR/>6     <BR/>Password:7     <inputtype= "text"ID= "Txt2"value= "Please enter your email password" />8     <inputtype= "Password"ID= "PSWD" />9 Ten     <BR/> One     <BR/> A     <inputtype= "button"ID= "BTN"value= "Login" /> - </form>

JS Code:

1 <Scripttype= "Text/javascript"CharSet= "Utf-8">2 DLSJ ('#txt1','Please enter your email address','#txt2','#pswd')   //called3 4 5 functionDLSJ (txt1,txt1_val,txt2,password) {6     //Email address input box get focus7 $ (TXT1). Focus (function(){8         varTxt1_value=$ (TXT1). Val ();9         if(Txt1_value==txt1_val) {Ten         $( This). Val ("'); One         } A     }) -  - //Email address input box loses focus the $ (TXT1). Blur (function(){ -         varTxt1_value=$ (TXT1). Val (); -         if(Txt1_value=="") -         $( This). Val (Txt1_val); { +         } -     }) +     var$txt 2_obj=$ (TXT2);//get the jquery object with ID txt2 A     var$pswd _obj=$ (password);//get the jquery object with ID txt2 at $txt 2_obj.focus (function(){ - $pswd _obj.show (). focus ();//Make password input box get focus - $txt 2_obj.hide ();//Hide text input box -  -    }) - $pswd _obj.blur (function(){ in          if($pswd _obj.val ()=="'){//When the password input box loses focus, the text input box appears if no characters are entered in the input box - $txt 2_obj.show (); to $pswd _obj.hide (); +          } -      the     }) * }     $ </Script>

Login event, mouse click on the input box to hide the default value event

Related Article

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.