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