1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 "http://www.w3.org/TR/html4/strict.dtd"> 3 4 <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 7 <title>val_test</title> 8 <meta name="author" content="Administrator" /> 9 <script type="text/javascript" src="script/jquery-1.12.2.js"></script> 10 <!-- Date: 2016-03-23 --> 11 </head> 12 <body> 13 <input type="text" id="address" value="请输入邮箱地址" /> 14 <input type="text" id="password" value="请输入邮箱密码" /> 15 <input type="button" value="登录" /> 16 <script type="text/javascript"> 17 $("#address").focus(function() { 18 var txt_value = $(this).val(); 19 if(txt_value=="请输入邮箱地址"){//或者用defaultValue。 20 $(this).val(""); 21 } 22 }); 23 24 $("#address").blur(function() { 25 var txt_value = $(this).val(); 26 if(txt_value==""){ 27 $(this).val("请输入邮箱地址"); 28 } 29 }); 30 31 $("#password").focus(function() { 32 var txt_value = $(this).val(); 33 if(txt_value=="请输入邮箱密码"){ 34 $(this).val(""); 35 } 36 }); 37 38 $("#password").blur(function() { 39 var txt_value = $(this).val(); 40 if(txt_value==""){ 41 $(this).val("请输入邮箱密码"); 42 } 43 }); 44 </script> 45 </body> 46 </html>