如何打开和关闭 google-maps 自动完成功能? [英] How to toggle the google-maps autocomplete on and off?

查看:36
本文介绍了如何打开和关闭 google-maps 自动完成功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Google Maps API(级别 3)实例化一个自动完成输入,如下所示:

I'm instantiating an autocomplete input for Google Maps API (level 3), like so:

var input = document.getElementById('szukanyAdres');
autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);

如何在运行时打开和关闭自动完成功能?

How to turn the autocompletion functionality on and off at runtime?

推荐答案

有两个元素与自动完成相关

There are two elements related to the autocomplete

  1. 输入元素
  2. 一个包含列表条目的 div.此 div 将附加到正文并具有pac-container"类

那么您可以做什么:通过修改它们的显示样式来显示或隐藏这两个元素.

So what you can do: show or hide both elements by modifying their display-style.

当无法隐藏输入时,您可以用输入的克隆替换输入,这将删除自动完成功能.

When it's not possible to hide the input you may replace the input with a clone of the input, this will remove the autocomplete-functionality.

inputObject.parentNode.replaceChild(inputObject.cloneNode(true),input);

要恢复自动完成功能,请再次执行您想做的操作.

To restore the autocomplete do again what you want to do.

这篇关于如何打开和关闭 google-maps 自动完成功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆