ott*_*tz0 7 javascript google-api
我正在使用 Google 自动完成并收到此错误
InvalidValueError: not an instance of HTMLInputElement
Run Code Online (Sandbox Code Playgroud)
我认为谷歌有 getElementById 用于降价
var input = /** @type {!HTMLInputElement} */(
document.getElementById('pac-input'));
Run Code Online (Sandbox Code Playgroud)
但是我不确定它的用法。我的代码如下
var options ={
types:['(cities)'],
};
var input = document.getElementById('destination');
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
google.maps.event.addDomListener(window, 'load', initialize);
Run Code Online (Sandbox Code Playgroud)
use*_*671 -2
这是因为您覆盖了输入变量。如果您只使用 var input = /** @type {!HTMLInputElement} */( document.getElementById('pac-input')); 应该可以工作 或将“pac-input”替换为“destination”