gpt4 book ai didi

javascript - 谷歌地图自动完成总是选择第一项

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:34:28 25 4
gpt4 key购买 nike

<分区>

我正在使用 Google Maps Places V3 自动完成功能。我想要一个功能,如果用户开始在搜索字段中输入内容,自动完成下拉列表中的第一项将被自动选中。

类似于 Facebook 中的搜索功能。

我已经在这两个线程的帮助下更新了 Google map 的自动完成功能:

但是我找不到这个新问题的解决方案....

我在这里发布了我的代码: http://jsfiddle.net/Chazz09/YfPv3/5/

$(document).ready(function(){
var pac_input = document.getElementById('searchfield');
// prevents enter key to submit form//
$('#searchfield').keydown(function (e) {
if (e.which == 13 && $('.pac-container:visible').length) return false;
});
// prevents enter key to submit form//

(function pacSelectFirst(input){
// store the original event binding function
var _addEventListener = (input.addEventListener) ? input.addEventListener : input.attachEvent;

function addEventListenerWrapper(type, listener) {
// Simulate a 'down arrow' keypress on hitting 'return' when no pac suggestion is selected,
// and then trigger the original listener.

if (type == "keydown") {
var orig_listener = listener;
listener = function (event) {
var suggestion_selected = $(".pac-item.pac-selected").length > 0;
if (event.which == 13 && !suggestion_selected) {
var simulated_downarrow = $.Event("keydown", {keyCode:40, which:40})
orig_listener.apply(input, [simulated_downarrow]);
}

orig_listener.apply(input, [event]);
};
}

// add the modified listener
_addEventListener.apply(input, [type, listener]);
}

if (input.addEventListener)
input.addEventListener = addEventListenerWrapper;
else if (input.attachEvent)
input.attachEvent = addEventListenerWrapper;

})(pac_input);

$(document).ready(function()
{
function initialize() {
var options = {
types: ['geocode'],
componentRestrictions: {country: "fr"}
};
var autocomplete = new google.maps.places.Autocomplete(pac_input, options);
}
google.maps.event.addDomListener(window, 'load', initialize);
});
});

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com