- <div class="search">
- <p>
- <a class="h_black" href="#" onclick="javascript:search_set_site(this,'/tags/{word}.shtm')" >站内</a> |
- <a class="h_blue1" href="#" onclick="javascript:search_set_site(this,'http://www.baidu.com/s?ie=utf-8&word={word}',encodeURI)">百度</a> |
- <a class="h_blue1" href="#" onclick="javascript:search_set_site(this,'http://www.google.cn/search?hl=zh-CN&q={word}',encodeURI)">谷歌</a> |
- <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> |
- <a class="h_blue1" href="#" onclick="javascript:search_set_site(this,'http://tieba.baidu.com/f?kw={word}')">帖吧</a> |
- <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> |
- <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> |
- <a class="h_blue1" href="#" onclick="javascript:search_set_site(this,'http://dict.iciba.com/{word}/')">词典</a> |
- <a class="h_blue1" href="#" onclick="javascript:search_set_site(this,'http://news.baidu.com/ns?tn=news&word={word}');">新闻</a>
- </p>
- <p>
- <input type="hidden" id="search_site" value="/tags/{word}.shtm"/>
- <input id="search_text" type="text" class="headinput_gray" onkeydown="javascript:if(event.keyCode==13){search_submit();}" />
- <input id="search_submit" type="button" class="headinput_b" style="cursor:pointer;" value="我要搜索" onclick="javascript:search_submit();" />
- </p>
- <p>
- <span class="h_black2">搜索焦点:</span>
- <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">魔兽世界</a>
- <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">天龙八部</a>
- <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">诛仙</a>
- <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">跑跑卡丁车</a>
- <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">热血传奇</a>
- <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">赤壁</a>
- <a class="h_blue2" href="#" onclick="javascript:search_set_word(this)">梦幻西游</a>
- </p>
- </div>
调用的JS文件内容:
- <script type="text/javascript">
- var search_encodefn;
- //字符串长度
- String.prototype.unicodeLength=function(){
- var length=0;
- for(var index=0,len=this.length;index<len;index++){
- if(this.charCodeAt(index)>255) length+=2;
- else length++;
- }
- return length;
- }
- //搜索
- function search_set_site(obj,site,fun){
- var p=obj.parentNode;
- for(var index=0,length=p.childNodes.length;index<length;index++){
- var tag=p.childNodes[index];
- if(tag.tagName=='A'){
- tag.className=tag==obj?"h_black":"h_blue1";
- }
- }
- function search_set_word(obj){
- document.getElementById('search_text').value=obj.innerHTML;
- }
- function search_submit(){
- var word=document.getElementById('search_text').value;
- if(word.length == 0 || word == "")//搜索为空
- {
- if(document.getElementById('search_site').value != '/tags/{word}.shtm')
- {
- window.open(document.getElementById('search_site').value.replace('{word}',""));
- }
- }
- else//搜索不为空
- {
- if (document.getElementById('search_site').value=='/tags/{word}.shtm')
- {
- word=word.replace(".","%2E");
- }
- if(typeof(search_encodefn)=='function'){
- word=search_encodefn(word)
- }
- window.open(document.getElementById('search_site').value.replace('{word}',word));
- }
- }
- </script>