1. <html xmlns="http://www.w3.org/1999/xhtml"> 
  2. <head> 
  3. <title>CSS美化的漂亮搜索框 - www.cxybl.com</title> 
  4. <meta http-equiv="content-type" content="text/html;charset=gb2312"> 
  5. <style type="text/css"> 
  6. <!-- 
  7. .search{ 
  8. padding-right:10px; 
  9. padding-left:10px; 
  10. padding-top:5px; 
  11. padding-bottom:5px; 
  12. width: 280px; 
  13. background:#1A93CC; 
  14. float:left; 
  15. position:relative; 
  16. .search .input{ 
  17. padding-top:2px; 
  18. height:16px; 
  19. width: 180px; 
  20. border: 1px solid #0086C6; 
  21. font-size:14px; 
  22. background:#fff url(search_btn.gif) no-repeat right 0; 
  23. .label{ 
  24. color:#ccc; 
  25. position:absolute; 
  26. left:12px;top:6px; 
  27. display:block; 
  28. height:22px; 
  29. line-height:22px; 
  30. font-size:12px; 
  31. span.submit{ 
  32. cursor:pointer; 
  33. position:absolute; 
  34. left:171px; 
  35. top:6px; 
  36. width:20px; 
  37. height:20px; 
  38. text-indent:-999em; 
  39. --> 
  40. </style> 
  41. </head> 
  42. <body> 
  43. <div class="search"> 
  44. <form action="" method="post" name="search" id="search"> 
  45. <input name="keyword" type="text" class="input" id="keyword" value="" style="float:left;"> 
  46. <label for="keyword" id="for-keyword" class="label">我要搜索</label> 
  47. <span class="submit" onclick="return formSubmit('frmsearch');">搜索</span> 
  48. </form> 
  49. </div> 
  50. <script type="text/javascript"> 
  51. var $ = function(id){return document.getElementById(id);} 
  52. var formSubmit = function(id){ 
  53. document.forms[id].submit(); 
  54. return false; 
  55. var tip = function(q, for_q){ 
  56. q = $(q); 
  57. for_q = $(for_q); 
  58. q.onfocus = function(){ 
  59. for_q.style.display = 'none'
  60. q.style.backgroundPosition = "right -17px"
  61. q.onblur = function(){ 
  62. if(!this.value) for_q.style.display = 'block'
  63. q.style.backgroundPosition = "right 0"
  64. for_q.onclick = function(){ 
  65. this.style.display = 'none'
  66. q.focus(); 
  67. }; 
  68. tip('keyword','for-keyword'); 
  69. </script> 
  70. </body> 
  71. </html>