天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

用javascript打造搜索工具欄

一:最終效果

二:原理

如果你在Yahoo中搜索“中國”,那么在瀏覽器的地址欄將得到這樣一串地址: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=
看上去有些亂了,簡化一下:http://search.cn.yahoo.com/search?&p=%D6%D0%B9%FA
這就是關鍵.其中&p=%D6%D0%B9%FA是搜索的關鍵字參數,而%D6%D0%B9%FA是“中國”的
Url編碼。OK,我們只要能構造出這樣的編碼就好了。

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

四:代碼
(點擊加號展開)
復制代碼 代碼如下:
 <%@ 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技術用javascript打造搜索工具欄,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 久久人妻少妇嫩草AV無碼 | 长泽梓黑人初解禁bdd07 | 私人玩物黑丝 | 99精品欧美一区二区三区美图 | 国产人妻麻豆蜜桃色 | 国产网站免费观看 | 2022国产91精品久久久久久 | 爆操日本美女 | 久久精品久久久 | 欧美性最猛xxxx在线观看视频 | 国产高清视频免费在线观看 | 超碰久久国产vs | 亚洲精品国产精品精 | 久久久影院亚洲精品 | 久久精品国产福利电影网 | 欧美一级久久久久久久大 | 欧美含羞草免费观看全部完 | 羞羞一区二区三区四区片 | 美女乱草鲍高清照片 | 一本之道高清在线观看一区 | 国产免费播放一区二区三区 | 俄罗斯性xxxx | 国产探花在线精品一区二区 | 国产99久久亚洲综合精品西瓜tv | 国产婷婷一区二区在线观看 | 久久久久毛片免费观看 | 亚洲 欧美 日韩 国产 视频 | 亚洲日韩一区精品射精 | 亚洲 日本 天堂 国产 在线 | 一边吃奶一边添P好爽故事 一边吃奶一边啪啪真舒服 一本之道加勒比在线观看 一本之道高清在线观看一区 | 高清国语自产拍免费 | 5G年龄确认我已满18免费 | 久久婷婷五月免费综合色啪 | 日韩欧美中文字幕在线二视频 | 野花日本免费完整版高清版动漫 | 久久强奷乱码老熟女 | 日日撸影院在线 | 好好的曰com久久 | 91九色视频无限观看免费 | xxxxxl荷兰| 最新国自产拍天天更新 |