標籤:
實現效果:將滑鼠聚焦到郵箱地址文字框時,文字框 內的“請輸入郵箱地址”文字將被清除;
若沒有輸入任何內容,滑鼠移除後郵箱地址文字框被還原。
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>註冊</title> 6 <!-- <link rel="stylesheet" href="css/default.css" type="text/css" /> --> 7 8 <script type="text/javascript" src="../scripts/jquery-1.7.2.js"></script> 9 <script type="text/javascript">10 $(function(){11 $("#mailaddress").focus(function(){12 var txt_val = $(this).val();13 if (txt_val == "請輸入郵箱地址") {14 $(this).val("");15 }16 });17 18 $("#mailaddress").blur(function(){19 var txt_val = $(this).val();20 if (txt_val == "") {21 $(this).val("請輸入郵箱地址");22 }23 });24 $("#password").focus(function(){25 var txt_val = $(this).val();26 if (txt_val == "請輸入郵箱密碼") {27 $(this).val("");28 }29 });30 31 $("#password").blur(function(){32 var txt_val = $(this).val();33 if (txt_val == "") {34 $(this).val("請輸入郵箱密碼");35 }36 });37 38 39 });40 </script>41 </head>42 <body>43 <input type="text" id="mailaddress" value="請輸入郵箱地址"/> <br/><br/>44 <input type="text" id="password" value="請輸入郵箱密碼"/> <br/><br/>45 <input type="button" value="登入"/>46 </body>47 </html>
jQuery實現登入提示