Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)delv
published in(发表于) 2013/12/31 6:42:00
用javascript打造搜索工具栏_JavaScript技术_编程技术

用javascript打造搜索工具栏_JavaScript技术_编程技术-你的首页-uuhomepage.com





电子科技大学软件学院03级2班 周银辉




一:最终效果




二:原理




如果你在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(“中国”);来完成。




四:代码
(点击加号展开)




1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Search.aspx.cs" Inherits="Search" %>
2
3 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5 http://www.w3.org/1999/xhtml" >
6
7 Search
8
78
79
80
81


82

83

84 Search

85

86

87

88

89
90
91
92 Key
93
94
95
96 97 Style="position: relative" Font-Names="terminal">
98 Web
99 Mp3
100 Image
101

102
103
104
105
106
107
108 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
109 110 value="Yahoo!" onclick="return Button_Yahoo_onclick()" />
111
112
113

114

115 Home
116
117











If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759