搜索功能,并且能指定到象google/baidu/sina等搜索里面去

 
  1. <div class="search">
  2.   <p>
  3.     <a class="h_black" href="#" onclick="javascript:search_set_site(this,'/tags/{word}.shtm')" >站内</a> | 
  4.     <a class="h_blue1" href="#" onclick="javascript:search_set_site(this,'http://www.baidu.com/s?ie=utf-8&word={word}',encodeURI)">百度</a> | 
  5.     <a class="h_blue1" href="#" onclick="javascript:search_set_site(this,'http://www.google.cn/search?hl=zh-CN&q={word}',encodeURI)">谷歌</a> | 
  6.     <a class="h_blue1" href="#" onclick="javascript:search_set_site(this,'http://www.baidu.com/i?ct=201326592&cl=2&lm=-1&tn=baiduimage&word={word}')">图片</a> | 
  7.     <a class="h_blue1" href="#" onclick="javascript:search_set_site(this,'http://tieba.baidu.com/f?kw={word}')">帖吧</a> | 
  8.     <a class="h_blue1" href="#" onclick="javascript:search_set_site(this,'http://mp3search.baidu.com/wstsearch?tn=baidump3&ct=134217728&lm=-1&rn=&word={word}')">音乐</a> | 
  9.     <a class="h_blue1" href="#" onclick="javascript:search_set_site(this,'http://video.baidu.com/v?ct=301989888&rn=20&pn=0&db=0&s=0&word={word}')">视频</a> | 
  10.     <a class="h_blue1" href="#" onclick="javascript:search_set_site(this,'http://dict.iciba.com/{word}/')">词典</a> | 
  11.     <a class="h_blue1" href="#" onclick="javascript:search_set_site(this,'http://news.baidu.com/ns?tn=news&word={word}');">新闻</a>
  12.   </p>
  13. <p>
  14.   <input type="hidden" id="search_site" value="/tags/{word}.shtm"/>
  15.   <input id="search_text" type="text" class="headinput_gray" onkeydown="javascript:if(event.keyCode==13){search_submit();}" />
  16.   <input id="search_submit" type="button" class="headinput_b" style="cursor:pointer;" value="我要搜索" onclick="javascript:search_submit();" />
  17. </p> 
  18. <p>
  19.   <span class="h_black2">搜索焦点:</span>
  20.   <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">魔兽世界</a>
  21.   <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">天龙八部</a>
  22.   <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">诛仙</a>
  23.   <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">跑跑卡丁车</a>
  24.   <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">热血传奇</a>
  25.   <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">赤壁</a>
  26.   <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">梦幻西游</a>
  27.  </p>
  28. </div>

调用的JS文件内容:

  1. <script type="text/javascript">
  2. var search_encodefn;
  3. //字符串长度
  4. String.prototype.unicodeLength=function(){
  5.     var length=0;  
  6.     for(var index=0,len=this.length;index<len;index++){  
  7.         if(this.charCodeAt(index)>255)   length+=2;  
  8.         else   length++;  
  9.     }  
  10.     return  length;   
  11. }
  12. //搜索
  13. function search_set_site(obj,site,fun){
  14.   var p=obj.parentNode;
  15.   for(var index=0,length=p.childNodes.length;index<length;index++){
  16.       var tag=p.childNodes[index];
  17.       if(tag.tagName=='A'){
  18.         tag.className=tag==obj?"h_black":"h_blue1";
  19.       }
  20.   }
  21. function search_set_word(obj){
  22.   document.getElementById('search_text').value=obj.innerHTML;
  23. }
  24. function search_submit(){
  25.     var word=document.getElementById('search_text').value;
  26.     if(word.length == 0 || word == "")//搜索为空
  27.     {
  28.         if(document.getElementById('search_site').value != '/tags/{word}.shtm')
  29.         {
  30.             window.open(document.getElementById('search_site').value.replace('{word}',""));
  31.         }
  32.     }
  33.     else//搜索不为空
  34.     {
  35.         if (document.getElementById('search_site').value=='/tags/{word}.shtm')
  36.         {
  37.           word=word.replace(".","%2E");
  38.         }
  39.         if(typeof(search_encodefn)=='function'){
  40.          word=search_encodefn(word)
  41.         }
  42.         window.open(document.getElementById('search_site').value.replace('{word}',word));
  43.     } 
  44. }
  45. </script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值