[英]how can i turn Jquery UI autocomplete into links?
i was trying out the jquery ui autocomplete and its pretty easy to implment and i loved it, but im finding it confusing to make the suggestions linkable just like google search,ie when you click on it it takes you to another page. 我正在尝试jQuery ui自动完成功能,它很容易实现,我很喜欢它,但是我发现它难以使建议像Google搜索一样可链接,即当您单击它时,它会将您带到另一个页面。
$(function() {
$("#state").autocomplete({
source: "states.php",
minLength: 2,
select: function(event, ui) {
$('#state_id').val(ui.item.id);
$('#abbrev').val(ui.item.abbrev);
}
});
});
this is an example of the jquery script, thanks for your help:)) 这是jquery脚本的示例,感谢您的帮助:))
If I understand correctly, you just need a line like: 如果我理解正确,则只需要这样一行:
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.
in your select : function(event,ui){ ... }
在您的
select : function(event,ui){ ... }
you can add a callback function to the select event. 您可以向select事件添加回调函数。
$( ".selector" ).autocomplete({
select: function(event, ui) { ... }
});
there you could redirect to the link you want. 在那里您可以重定向到所需的链接。
window.location.href = "http://stackoverflow.com";
Sorry I just saw you have already the callback function added. 抱歉,我刚刚看到您已经添加了回调函数。 so you only need to redirect.
因此您只需要重定向。
该示例将使您进入正确的位置: http : //jqueryui.com/demos/autocomplete/#custom-data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.