All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
用javascript打造搜索工具栏_JavaScript技术_编程技术

Writer: delv Article type: Programming skills(编程技巧) Time: 2013/12/31 6:42:00 Browse times: 406 Comment times: 0

用javascript打造搜索工具栏_JavaScript技术_编程技术


Head photo

Go homepage
Upload pictures
Write articles

用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
























There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.