我正在尝试使用jquery ui自动完成功能,它非常容易实现,我很喜欢它,但我发现令人困惑的是将建议链接起来就像谷歌搜索一样,即当你点击它时会带你到另一个页面。
$(function() {
$("#state").autocomplete({
source: "states.php",
minLength: 2,
select: function(event, ui) {
$('#state_id').val(ui.item.id);
$('#abbrev').val(ui.item.abbrev);
}
});
});
这是jquery脚本的一个示例,感谢您的帮助:))
答案 0 :(得分:3)
如果我理解正确,你只需要一行:
window.location="http://place/to/link/to.php?" + ui.item.abbrev; //This would send you to a php script accepting ui.item.abbrev as a parameter.
在select : function(event,ui){ ... }
答案 1 :(得分:2)
您可以为select事件添加回调函数。
$( ".selector" ).autocomplete({
select: function(event, ui) { ... }
});
你可以重定向到你想要的链接。
window.location.href = "http://stackoverflow.com";
抱歉,我刚看到你已经添加了回调功能。 所以你只需要重定向。
答案 2 :(得分:0)
此示例可让您前往正确的位置:http://jqueryui.com/demos/autocomplete/#custom-data