DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> Google AJAX 搜索 API實現代碼
Google AJAX 搜索 API實現代碼
編輯:關於JavaScript     

Google AJAX 搜索 API
文檔:http://code.google.com/intl/zh-CN/apis/websearch/docs/

復制代碼 代碼如下:
<!DOCTYPE html>
<html>
<head>
<title>Google AJAX 搜索 API</title>
<style type="text/css">
#searchcontrol .gsc-control
{
width: 100%;
}
#searchcontrol .gsc-result-cnblogs .gs-title
{
color:Red;
}
</style>
<script src="https://www.google.com/jsapi?key=ABQIAAAAWUT8aaIj9mtqQa087LjVOhTPB5B7LRDljl2Cr4-
JwBNft1mFrRRmR1RoYEUCZCj0dtS2gIc8Al4-VA"
type="text/javascript"></script>
<script language="Javascript" type="text/javascript">
google.load("search", "1");

function OnLoad() {
//搜索設置
var options = new google.search.SearcherOptions();
//當搜索結果為空時顯示內容
options.setNoResultsString('查詢結果為空!');

//搜索控件實例化
var searchControl = new google.search.SearchControl();
//每次顯示8個搜索結果(取值范圍:1-8)
searchControl.setResultSetSize(8);

//網頁搜索
var siteCnblogs = new google.search.WebSearch();
//標頭
siteCnblogs.setUserDefinedLabel("");
//樣式後綴名
siteCnblogs.setUserDefinedClassSuffix("jb51");
//站點限制
siteCnblogs.setSiteRestriction("jb51.net");
searchControl.addSearcher(siteCnblogs, options);

//局部搜索
var siteZjfree = new google.search.WebSearch();
siteZjfree.setUserDefinedLabel("素材搜索");
siteZjfree.setSiteRestriction("sc.jb51.net");
searchControl.addSearcher(siteZjfree, options);

//全網搜索
searchControl.addSearcher(new google.search.WebSearch(), options);

//添加博客搜索
searchControl.addSearcher(new google.search.BlogSearch(), options);

//添加視頻搜索
searchControl.addSearcher(new google.search.VideoSearch(), options);

//添加新聞搜索
searchControl.addSearcher(new google.search.NewsSearch(), options);

//添加圖片搜索
searchControl.addSearcher(new google.search.ImageSearch(), options);

//添加本地地圖搜索
var localSearch = new google.search.LocalSearch();
//地圖中心標記 測試時可使用“大雁塔”
localSearch.setCenterPoint("西安,鐘樓");
searchControl.addSearcher(localSearch, options);

//繪制搜索
var drawOptions = new google.search.DrawOptions();
drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
searchControl.draw(document.getElementById("searchcontrol"), drawOptions);

//執行搜索查詢
searchControl.execute("google api");
}

//框架加載完成後調用
google.setOnLoadCallback(OnLoad);
</script>
</head>
<body>
<div id="searchcontrol">
加載中...
</div>
</body>
</html>

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved