執行個體解惑:怎麼做類似yahoo的搜尋方塊?

來源:互聯網
上載者:User
yahoo

  本文及代碼由 renx 原創,希望能給各位網友帶來協助。

  開始

  為了做這個yahoo搜尋方塊,我分了三步:

  1. 先做搜尋分類的按鈕,點擊後會和其他按鈕看上去比較不一樣,這個是挺簡單的

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <title>search_bar</title>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  <style>
  body,html {
  font-size:12px;
  }
  .none {display: none;}
  .block {display: block;}
  .s_c {width:800px;text-align: center;}
  .s_c ul{clear:both;margin:0;}
  .s_c li{list-style:none;float:left;position: relative;width: 70px;}
  .c_0 {padding:0px 10px 0px 10px;line-height:22px}
  .c_0 a{color:#666;text-decoration: none;}
  .c_1 {padding:4px 0;width: 70px;
  background:#0075eb;border:1px solid #054576;border-bottom-width:0;text-decoration: none;}
  .c_1 a{color:#FFF;font-weight:bold;text-decoration: none;}
  .c_2 {padding:4px 0;width: 70px;background:#a10303;border:1px solid #662626;border-bottom-width:0;}
  position: absolute;bottom: -7px;left: 0;}
  .c_3 {padding:4px 0;width: 70px;background:#B01FAA;border:1px solid #760473;border-bottom-width:0;}
  .white a {color:#FFF;font-weight:bold;text-decoration: none;}
  </style>
  <script language="javascript">
  function aa(s_id){
  for(i=1;i<4;i++){
  if(i==s_id){
  document.getElementById("m"+i).className="c_"+i+" white";
  }
  else {
  document.getElementById("m"+i).className="c_0";
  }
  }
  }
  </script>
  </head>
  <body>
  <div class="s_c"><ul>
  <li><div id="m1" class="c_1"><a href="###" >分類第一</a></div></li>
  <li><div id="m2" class="c_0"><a href="###" >分類第二</a></div></li>
  <li><div id="m3" class="c_0"><a href="###" >分類第三</a></div></li>
  </ul>
  </div>
  </body>
  </html>

  當然這還不夠,接下來實現第二步效果。

  2.加個搜尋輸入框,而且要能換顏色的

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <title>search_bar</title>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  <style>
  body,html {
  font-size:12px;
  }
  .none {display: none;}
  .block {display: block;}
  .s_c {width:800px;text-align: center;}
  .s_c ul{clear:both;margin:0;}
  .s_c li{list-style:none;float:left;position: relative;width: 70px;}
  .s_b {border:1px solid #666;}
  .s_b span{padding:20px 20px;vertical-align:middle;}
  .s_b input{margin:8px 8px;}
  .search_0 {background:#fff;}
  .search_1 {background:#d2e4fc;}
  .search_2 {background:#fcd2d2;}
  .search_3 {background:#F9D3FA;}
  .search_4 {background:#defbfb;}
  .search_5 {background:#fce8d2;}
  .search_6 {background:#FCEBB9;}
  .c_0 {padding:0px 10px 0px 10px;line-height:22px}
  .c_0 a{color:#666;text-decoration: none;}
  .c_1 {padding:4px 0;width: 70px;
  background:#0075eb;border:1px solid #054576;border-bottom-width:0;text-decoration: none;}
  .c_1 a{color:#FFF;font-weight:bold;text-decoration: none;}
  .c_2 {padding:4px 0;width: 70px;background:#a10303;border:1px solid #662626;border-bottom-width:0;}
  position: absolute;bottom: -7px;left: 0;}
  .c_3 {padding:4px 0;width: 70px;background:#B01FAA;border:1px solid #760473;border-bottom-width:0;}
  .white a {color:#FFF;font-weight:bold;text-decoration: none;}
  </style>
  <script language="javascript">
  function aa(s_id){
  for(i=1;i<4;i++){
  if(i==s_id){
  document.getElementById("s"+i).className="block be";
  document.getElementById("m"+i).className="c_"+i+" white";
  document.getElementById("uid_"+i).focus();
  }
  else {
  document.getElementById("s"+i).className="none";
  document.getElementById("m"+i).className="c_0";
  }
  }
  }
  </script>
  </head>
  <body>
  <div class="s_c"><ul>
  <li><div id="m1" class="c_1"><a href="###" >分類第一</a></div></li>
  <li><div id="m2" class="c_0"><a href="###" >分類第二</a></div></li>
  <li><div id="m3" class="c_0"><a href="###" >分類第三</a></div></li>
  </ul>
  </div>
  <div class="s_b">
  <div class="block" id="s1"><div class="search_1"><span>Search the Web:</span><input name="uid" id="uid_1" /><span>按鈕</span></div></div>
  <div class="none" id="s2"><div class="search_2"><span>Search the Web:</span><input name="uid" id="uid_2" /><span>按鈕</span></div></div>
  <div class="none" id="s3"><div class="search_3"><span>Search the Web:</span><input name="uid" id="uid_3" /><span>按鈕</span></div></div>
  </div>
  </body>
  </html>

  3. 現在加個箭頭,做個外框,當然也要不同顏色的

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <title>search_bar</title>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  <style>
  body,html {
  font-size:12px;
  }
  .none {display: none;}
  .block {display: block;}
  .s_c {width:800px;text-align: center;}
  .s_c ul{clear:both;margin:0;}
  .s_c li{list-style:none;float:left;position: relative;width: 70px;}
  .s_b {border:1px solid #666;}
  .s_b span{padding:20px 20px;vertical-align:middle;}
  .s_b input{margin:8px 8px;}
  .search_0 {background:#fff;}
  .search_1 {background:#d2e4fc;}
  .search_2 {background:#fcd2d2;}
  .search_3 {background:#F9D3FA;}
  .search_4 {background:#defbfb;}
  .search_5 {background:#fce8d2;}
  .search_6 {background:#FCEBB9;}
  .c_0 {padding:0px 10px 0px 10px;line-height:22px}
  .c_0 a{color:#666;text-decoration: none;}
  .c_1 {padding:4px 0;width: 70px;
  background:#0075eb;border:1px solid #054576;border-bottom-width:0;text-decoration: none;}
  .c_1 a{color:#FFF;font-weight:bold;text-decoration: none;}
  .c_1 b{width:100%;height:11px;background:url("picture/sc1.gif") no-repeat 50% bottom;position: absolute;bottom: -7px;left: 0;}
  .c_2 {padding:4px 0;width: 70px;background:#a10303;border:1px solid #662626;border-bottom-width:0;}
  .c_2 b{width:100%;height:11px;background:url("picture/sc2.gif") no-repeat 50% bottom;
  position: absolute;bottom: -7px;left: 0;}
  .c_3 {padding:4px 0;width: 70px;background:#B01FAA;border:1px solid #760473;border-bottom-width:0;}
  .c_3 b{width:100%;height:11px;background:url("picture/sc3.gif") no-repeat 50% bottom;position: absolute;bottom: -7px;left: 0;}
  .c_4 {padding:4px 0;width: 70px;background:#41abb5;border:1px solid #297a80;border-bottom-width:0;}
  .c_4 b{width:100%;height:11px;background:url("picture/sc4.gif") no-repeat 50% bottom;position: absolute;bottom: -7px;left: 0;}
  .c_5 {padding:4px 0;width: 70px;background:#d95000;border:1px solid #96450c;border-bottom-width:0;}
  .c_5 b{width:100%;height:11px;background:url("picture/sc5.gif") no-repeat 50% bottom;position: absolute;bottom: -7px;left: 0;}
  .c_6 {padding:4px 0;width: 70px;background:#ec9e2e;border:1px solid #B28B12;border-bottom-width:0;}
  .c_6 b{width:100%;height:11px;background:url("picture/sc6.gif") no-repeat 50% bottom;position: absolute;bottom: -7px;left: 0;}
  .white a {color:#FFF;font-weight:bold;text-decoration: none;}
  </style>
  <script language="javascript">
  function aa(s_id){
  for(i=1;i<7;i++){
  if(i==s_id){
  document.getElementById("s"+i).className="block be";
  document.getElementById("m"+i).className="c_"+i+" white";
  document.getElementById("uid_"+i).focus();
  }
  else {
  document.getElementById("s"+i).className="none";
  document.getElementById("m"+i).className="c_0";
  }
  }
  }
  </script>
  </head>
  <body>
  <div class="s_c"><ul>
  <li><div id="m1" class="c_1"><a href="###" ><b></b>分類第一</a></div></li>
  <li><div id="m2" class="c_0"><a href="###" ><b></b>分類第二</a></div></li>
  <li><div id="m3" class="c_0"><a href="###" ><b></b>分類第三</a></div></li>
  <li><div id="m4" class="c_0"><a href="###" ><b></b>分類第四</a></div></li>
  <li><div id="m5" class="c_0"><a href="###" ><b></b>分類第五</a></div></li>
  <li><div id="m6" class="c_0"><a href="###" ><b></b>分類第六</a></div></li>
  </ul>
  </div>
  <div class="s_b">
  <div class="block" id="s1"><div class="search_1"><span>Search the Web:</span><input name="uid" id="uid_1" /><span>按鈕</span></div></div>
  <div class="none" id="s2"><div class="search_2"><span>Search the Images:</span><input name="uid" id="uid_2" /><span>按鈕</span></div></div>
  <div class="none" id="s3"><div class="search_3"><span>Search the Images:</span><input name="uid" id="uid_3" /><span>按鈕</span></div></div>
  <div class="none" id="s4"><div class="search_4"><span>Search the Audio</span><input name="uid" id="uid_4" /><span>按鈕</span></div></div>
  <div class="none" id="s5"><div class="search_5"><span>Search the News</span><input name="uid" id="uid_5" /><span>按鈕</span></div></div>
  <div class="none" id="s6"><div class="search_6"><span>Search the Shopping</span><input name="uid" id="uid_6" /><span>按鈕</span></div></div>
  </div>
  </body>
  </html>

  現在看來差不多可以了,就是效率有點低,下次再最佳化一下



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.