[JavaScript] jquery 文本框得到失去焦点 默认填充 →→→→→进入此内容的聊天室

来自 , 2019-09-01, 写在 JavaScript, 查看 103 次.
URL http://www.code666.cn/view/285a25c1
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title></title>
  6. <style type="text/css">
  7. body{
  8.         font:normal 12px/17px Arial;
  9. }
  10. div{
  11.     padding:2px;
  12. }
  13. input, textarea {
  14.          width: 12em;
  15.          border: 1px solid #888;
  16. }
  17. .focus {
  18.          border: 1px solid #f00;
  19.          background: #fcc;
  20. }
  21. </style>
  22. <!--   引入jQuery -->
  23. <script src="../scripts/jquery-1.3.1.js" type="text/javascript"></script>
  24. <script type="text/javascript">
  25.     $(function(){
  26.                 $(":input").focus(function(){
  27.                           $(this).addClass("focus");
  28.                           if($(this).val() ==this.defaultValue){  
  29.                   $(this).val("");          
  30.                           }
  31.                 }).blur(function(){
  32.                          $(this).removeClass("focus");
  33.                          if ($(this).val() == '') {
  34.                 $(this).val(this.defaultValue);
  35.              }
  36.                 });
  37.     })
  38.     </script>
  39.  
  40.  
  41. </head>
  42. <body>
  43.         <form action="" method="post" id="regForm">
  44.                 <fieldset>
  45.                         <legend>个人基本信息</legend>
  46.                                 <div>
  47.                                         <label  for="username">名称:</label>
  48.                                         <input id="username" type="text" value="名称" />
  49.                                 </div>
  50.                 <div>
  51.                                         <label for="pass">密码:</label>
  52.                                         <input id="pass" type="password" value="密码" />
  53.                                 </div>
  54.                 <div>
  55.                                         <label for="msg">详细信息:</label>
  56.                                         <textarea id="msg" rows="2" cols="20">详细信息</textarea>
  57.                                 </div>
  58.                 </fieldset>
  59.         </form>
  60. </body>
  61. </html>

回复 "jquery 文本框得到失去焦点 默认填充"

这儿你可以回复上面这条便签

captcha