Original link:
http://www.cnblogs.com/q460021417/p/4353554.html
CSS:
1 <style> 2 #txt1,#txt2{ color:#CCC; border:1px solid #666;} 3 #pswd{ display:none;border:1px solid #666;} 4 </style>
JS reference library:
1 <script src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
HTML:
. 1 < form ID = "MyForm" Action = "#" > 2 Address: . 3 < INPUT type = "text" ID = "the txt1" value = "Please enter the email address" /> . 4 . 5 < br /> . 6 < br / > password: 7 < the iNPUT of the type = "text" the above mentioned id = "txt2" value = "enter mailbox password" /> 8 < the iNPUT of the type = "password" id="pswd" /> 9 10 <br /> 11 <br /> 12 <input type="button" id="btn" value="登陆" /> 13 </form>
JS code:
. 1 < Script type = "text / JavaScript" charset = "UTF-. 8" > 2 dlsj ( ' # the txt1 ' , ' enter the email address ' , ' # txt2 ' , ' #pswd ' ) // call . 3 . 4 . 5 function dlsj (the txt1, txt1_val, txt2, password) { . 6 // e-mail address input box acquired focus . 7 $ (the txt1) .focus ( function () { . 8 var txt1_value = $ (the txt1) .val (); . 9 IF(txt1_value == txt1_val) { 10 $ ( the this ) .val ( '' ); . 11 } 12 is }) 13 is 14 // e-mail address input box loses focus 15 $ (the txt1) .blur ( function () { 16 var txt1_value = $ (the txt1) .val (); . 17 IF (txt1_value == "" ) 18 is $ ( the this ) .val (txt1_val); { . 19 } 20 is }) 21 is var $ txt2_obj = $ (txt2); //Gets the id of txt2 jquery object 22 is var $ pswd_obj = $ (password); // Get jquery object id is a txt2 23 is $ txt2_obj.focus ( function () { 24 $ pswd_obj.show () Focus ();. // focus acquisition enable password input box 25 $ txt2_obj.hide (); // hides the text input box 26 is 27 }) 28 $ pswd_obj.blur ( function () { 29 IF ($ pswd_obj.val () == '' ) { / / after the password input box loses focus, if there is no input character input box, the text input box appears 30 $ txt2_obj.show (); 31 $ pswd_obj.hide (); 32 } 33 34 }) 35 } 36 </script>
Reproduced in: https: //www.cnblogs.com/q460021417/p/4353554.html