javascript - Google Places API 无效值错误 : not an instance of HTMLInputElement

标签 javascript html google-places-api

有一个包含此元素的 HTML 表单:

var control = container.getElementById('AutoComplete');
var input = /** @type {!HTMLInputElement} */ (control);
console.log("input: ", input); //Output: <input type=​"text" id=​"AutoComplete" placeholder=​"--" class=​"block_input" autocomplete=​"off">​
autocomplete = new google.maps.places.Autocomplete(input, {
  types: ['geocode']
});
<html>
<div id="input_address">
  <div class="element">
    <label class="block_label">Адрес</label>
  </div>
  <div class="element">
    <input type="text" id="AutoComplete" placeholder="--" class="block_input"></input>
  </div>
</div>

</html>

我有一个错误:

not an instance of HTMLInputElement

我该如何解决这个问题?

最佳答案

我也遇到了同样的问题,这个方法有效。

 let searchInputField = document.getElementsByClassName('search-form')[0].getElementsByTagName('input')[0];
 let autocomplete = new google.maps.places.Autocomplete(searchInputField);

关于javascript - Google Places API 无效值错误 : not an instance of HTMLInputElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42695109/

相关文章:

php - 如何删除 sql-database-array 中选定的值

ios - swift GMSPlacePicker 不显示 map

android - 如何根据当前位置设置正确的纬度和经度

google-places-api - 谷歌放置api餐厅类型

html - 甚至垂直和水平对齐 flexbox

javascript - 需要帮助了解如何对网站进行 ajax 化

javascript - Uncaught Error : Invariant Violation: findComponentRoot(. .., ...$110) : Unable to find element. 这可能意味着 DOM 意外发生了变化

javascript - 使用 Selenium 中文本前面的值递增变量

javascript - 添加/删除规则后如何使用 jQuery 重新验证表单?

javascript - 如何将滚动条附加到 div 部分?