Kra*_*ram 9 autocomplete google-search-api
我们正在使用Google自定义搜索API(付费服务器端API)来支持我们的搜索结果.
我想在搜索中添加一个自动完成功能 - 但是,是否有人知道是否支持此功能(通过服务器端API,还是通过某种客户端JSONP?)
我已尝试使用自动填充功能进行Google自定义搜索,但这似乎想要绘制搜索框并显示带有结果的Google广告,这是我不想要的.
Kra*_*ram 13
得到这样的工作 - 希望这有助于别人:)
$(function () {
$('input.search')
.focus(function () { this.select(); })
.mouseup(function (e) { e.preventDefault(); })
.autocomplete({
position: {
my: "left top",
at: "left bottom",
offset: "0, 5",
collision: "none"
},
source: function (request, response) {
$.ajax({
url: "http://clients1.google.com/complete/search?q=" + request.term + "&hl=en&client=partner&source=gcsc&partnerid={GOOGLESEARCHID}&ds=cse&nocache=" + Math.random().toString(),
dataType: "jsonp",
success: function (data) {
response($.map(data[1], function (item) {
return {
label: item[0],
value: item[0]
};
}));
}
});
},
autoFill: true,
minChars: 0,
select: function (event, ui) {
$(this).closest('input').val(ui.item.value);
$(this).closest('form').trigger('submit');
}
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8509 次 |
| 最近记录: |