1
我們正在使用Google自定義搜索引擎(Paid)。我們未使用Google搜索控件。如何以編程方式實現Autocomplete(查詢建議)功能。是否有自動完成如何啓用Google自定義搜索自動完成功能
我們正在使用Google自定義搜索引擎(Paid)。我們未使用Google搜索控件。如何以編程方式實現Autocomplete(查詢建議)功能。是否有自動完成如何啓用Google自定義搜索自動完成功能
您可以輕鬆地啓用自動完成您的GSS/CSE什麼特殊的API:
https://support.google.com/customsearch/answer/2631081?hl=en
然後等待一段時間,由谷歌生成自動autocompletitions。
如果 「不使用谷歌搜索控制」 是指 「我們使用的是普通的HTML表單」,那就試試這個:
<form id="searchForm" action="http://google.com/cse">
<input type="hidden" name="cx" value="013315504628135767172:d6shbtxu-uo" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="text" name="q" size="31" id="searchText" />
<input type="submit" name="sa" value="Search" />
</form>
<img src="//www.google.com/cse/images/google_custom_search_smwide.gif">
<script type="text/javascript" src="//www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('search', '1');
var autoCompletionOptions = {
'maxCompletions' : 3,
'styleOptions' : {
'xOffset' : 10
}};
google.setOnLoadCallback(function() {
google.search.CustomSearchControl.attachAutoCompletionWithOptions(
"013315504628135767172:d6shbtxu-uo", document.getElementById('searchText'), 'searchForm',
autoCompletionOptions);
});
</script>
當然,自動完成應啓用對於那個GSS/CSE(就像上面的鏈接中描述的那樣),不管你使用什麼 - CSE元素或者HTML表單。