【发布时间】:2023-03-09 05:24:01
【问题描述】:
我正在关注this 教程来实现 Google 地方信息自动完成功能。但是,这只适用于现有的静态定义的文本字段。在我的测试应用程序中,我动态添加了文本字段,用户单击按钮即可添加更多文本字段。
<input maxlength="40" name="Point[location][]" id="Point_location" type="text" placeholder="Enter a location" autocomplete="off">
<input maxlength="40" name="Point[location][]" id="Point_location2" type="text" placeholder="Enter a location" autocomplete="off">
这是我的javascript
<script>
var location = $("input[id^=Point_location]")[0];
var autocompleteLocation = new google.maps.places.Autocomplete(location, options);
google.maps.event.addListener(autocompleteLocation, 'place_changed', function () {
var placeLocation = autocompleteLocation.getPlace();
});
</script>
我似乎无法让自动完成功能处理任何带有 id Point_location 的现有输入或刚刚添加的输入。
感谢您对此的任何帮助。
【问题讨论】:
标签: javascript jquery google-maps-api-3 autocomplete google-places-api