- 论坛徽章:
- 0
|
为了看看实际效果,我们以 Google 提供的示例 Web 页面为例,对它稍做修改,然后看看它会变成什么样子。
创建搜索框
清单 1 显示了一个很简单的 Web 页面。将这段代码输入到您喜欢使用的编辑器中,保存为文件,然后将该文件上传到上个小节中提供给 Google 的域或 URL 上。
清单 1. 一个简单的 Google 搜索应用程序的 HTML 代码
<html>
<head>
<title>My Google AJAX Search API Application</title>
<link href="http://www.google.com/uds/css/gsearch.css"
type="text/css" rel="stylesheet" />
<script
src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=
YOUR KEY HERE
"
type="text/javascript"> </script>
<script language="Javascript" type="text/javascript">
function OnLoad() {
// Create the Google search control
var searchControl = new GSearchControl();
// These allow you to customize what appears in the search results
var localSearch = new GlocalSearch();
searchControl.addSearcher(localSearch);
searchControl.addSearcher(new GwebSearch());
searchControl.addSearcher(new GvideoSearch());
searchControl.addSearcher(new GblogSearch());
// Tell Google your location to base searches around
localSearch.setCenterPoint("Dallas, TX");
// "Draw" the control on the HTML form
searchControl.draw(document.getElementById("searchcontrol"));
}
</script>
</head>
<body onload="OnLoad()">
<div id="searchcontrol" />
</body>
</html> |
|