根据http://code.google.com/intl/sk-SK/apis/maps/documentation/javascript/places.html#places_autocomplete,我已成功在输入框中实施了Google Maps Places V3自动填充功能.它工作得很好,但我很想知道如何在用户按下回车时从建议中选择第一个选项.我想我需要一些JS魔法,但我对JS很新,不知道从哪里开始.
提前致谢!
我正在使用Google商家信息自动填充功能,我只是希望它在表单字段中按下回车键并且存在建议时选择结果列表中的顶部项目.我知道之前有人问过:
谷歌地图Places API V3自动完成 - 在输入时选择第一个选项
谷歌地图Places API V3自动完成 - 在输入时选择第一个选项(让它保持这种方式)
但这些问题的答案似乎并没有真正起作用,或者它们解决了特定的附加功能.
它看起来像下面的东西应该工作(但它没有):
$("input#autocomplete").keydown(function(e) {
if (e.which == 13) {
//if there are suggestions...
if ($(".pac-container .pac-item").length) {
//click on the first item in the list or simulate a down arrow key event
//it does get this far, but I can't find a way to actually select the item
$(".pac-container .pac-item:first").click();
} else {
//there are no suggestions
}
}
});
Run Code Online (Sandbox Code Playgroud)
任何建议将不胜感激!
javascript google-maps google-maps-api-3 google-places-api google-places