中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

用javascript打造搜索工具欄

一:最終效果

二:原理

如果你在Yahoo中搜索“中國(guó)”,那么在瀏覽器的地址欄將得到這樣一串地址:http://search.cn.yahoo.com/search?ei=gbk&fr=fp-tab-web-ycn&meta=vl%
3Dlang_zh-CN%26vl%3Dlang_zh-TW&pid=ysearch&source=ysearch_www_hp_button
&p=%D6%D0%B9%FA&Submit=
看上去有些亂了,簡(jiǎn)化一下:http://search.cn.yahoo.com/search?&p=%D6%D0%B9%FA
這就是關(guān)鍵.其中&p=%D6%D0%B9%FA是搜索的關(guān)鍵字參數(shù),而%D6%D0%B9%FA是“中國(guó)”的
Url編碼。OK,我們只要能構(gòu)造出這樣的編碼就好了。

三:URL編碼
JavaScript的encodeURIComponent()函數(shù)可以完成編碼工作。
比如上面的例子我們可以用“http://search.cn.yahoo.com/search?&p=”+encodeURIComponent(“中國(guó)”);來完成。

四:代碼
(點(diǎn)擊加號(hào)展開)
復(fù)制代碼 代碼如下:
 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Search.ASPx.cs" Inherits="Search" %>

 <!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 runat="server">
     <title>Search</title>
 <script language="Javascript" type="text/Javascript">
 // <!CDATA[

 function GetEncodeOfKey()
 {
     var strKey = window.document.getElementById("Text_Key").value;      
     return  encodeURIComponent(strKey); 
 }

 function GetUrl(site)
 {
     var encode=GetEncodeOfKey();

     //web
     if(document.getElementById("RadioButtonList_Kind_0").checked)
     {
         if(site=="google")
         {
             return "http://www.google.com/search?q="+encode+"&ei=UTF-8";
         }
         else
         {
             return "http://search.yahoo.com/search?p="+encode+"&ei=UTF-8";
         }
     }
     //mp3
     else if(document.getElementById("RadioButtonList_Kind_1").checked)
     {
         if(site=="google")
         {
             return "http://www.google.com/search?q="+encode+" mp3"+"&ei=UTF-8";
         }
         else
         {
             return "http://audio.search.yahoo.com/search/audio?&p="+encode+"&ei=UTF-8";

         }
     }
     //img
     else if(document.getElementById("RadioButtonList_Kind_2").checked)
     {
         if(site=="google")
         {
             return "http://images.google.com/images?q="+encode+"&ei=UTF-8";
         }
         else
         {
             return "http://images.search.yahoo.com/search/images?p="+encode+"&ei=UTF-8";
         }
     }
     else
     {
         //alert("err");
     }

     
 }

 function Button_Google_onclick() 
 {
     window.open(GetUrl("google"));
 }

 function Button_Yahoo_onclick() 
 {
     window.open(GetUrl("yahoo"));
 }

 // ]]>
 </script>
 </head>
 <body>
     <form id="form1" runat="server">
     <div>
         <br />
         <br />
         <strong><span style="font-size: 24pt; color: #336633">Search<br />
         </span></strong>
     </div>
     <hr style="position: relative" />
         <br />
         <table style="left: 0px; position: relative; top: 0px">
             <tr>
                 <td style="width: 31px; height: 21px">
                     <span style="font-family: Terminal">Key</span></td>
                 <td style="width: 253px; height: 21px">
                     <input id="Text_Key" style="width: 248px; position: relative" type="text" /></td>
                 <td style="width: 175px; height: 21px">
                     <ASP:RadioButtonList ID="RadioButtonList_Kind" runat="server" RepeatDirection="Horizontal"
                         Style="position: relative" Font-Names="terminal">
                         <ASP:ListItem Selected="True">Web</ASP:ListItem>
                         <ASP:ListItem>Mp3</ASP:ListItem>
                         <ASP:ListItem>Image</ASP:ListItem>
                     </ASP:RadioButtonList></td>
             </tr>
             <tr>
                 <td style="width: 31px">
                 </td>
                 <td colspan="2">
                     <input id="Button_Google" style="width: 80px; position: relative" type="button" value="Google" onclick="return Button_Google_onclick()" />
                              
                     <input id="Button_Yahoo" style="left: -29px; width: 104px; position: relative" type="button"
                         value="Yahoo!" onclick="return Button_Yahoo_onclick()" /></td>
         </table>
         <br />
         <hr style="position: relative" />
         <ASP:HyperLink ID="HyperLink_Home" runat="server" NavigateUrl="~/Default.ASPx" Style="position: relative">Home</ASP:HyperLink></form>
 </body>
 </html>

 

AspNet技術(shù)用javascript打造搜索工具欄,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 奇米在线| 国产一区二区三区欧美 | 中文字幕丁香5月 | 亚洲精品久久久久久一区二区 | 精品国产一区二区在线 | 日本黄色不卡视频 | 九色av | 自拍视频网站 | 欧美日韩不卡 | 国产精品揄拍一区二区 | 亚洲精品久久久久久久久久久久久 | 亚洲视频观看 | 91精品国产91久久久久久最新 | 久久网站免费视频 | 最新国产精品精品视频 | 91超碰在线 | 日韩中文字幕一区 | 欧美影院 | 超碰91在线 | 日韩在线免费视频 | 羞羞视频网站免费观看 | 国产原创在线观看 | 亚洲一区二区三区视频 | 国产免费一区 | 国产成人精品午夜 | 午夜成人免费视频 | 一区二区三区在线免费 | 在线观看免费观看在线91 | 日韩中文在线视频 | 久久成人综合 | 久久精彩视频 | 99精品一区| 久久久久国产一区二区三区 | 日韩欧美在线观看 | 黄色一级免费看 | 国产日韩中文字幕 | 在线永久看片免费的视频 | a亚洲精品 | 一区二区三区视频在线 | 五月精品视频 | 久草综合在线 |