我使用的标准谷歌自动完成功能无效。我必须在某处传递错误的值。当我输入一个字符时,自动完成会触发,它会删除用于结果的数据列表(locationAddressList)和从DOM中输入的字段(locationAddress)。
HTML
<section>Address<input id="locationAddress" class="address" type="text" list="locationAddressList" onkeyup="getGoogleAddresses('locationAddress');" />
<datalist id="locationAddressList" style="font-size:12px"></datalist>
</section>
这是函数调用:
function getGoogleAddresses(ID) {
var addressInput = "#" + ID;
var options = {
componentRestrictions: { country: "us" }
};
var autocomplete = new google.maps.places.Autocomplete($(addressInput)[0], options);
var places = $(addressInput).load(autocomplete);
//places = places.slice(0, -15);
$(addressInput + "List").append(places);