我正在按照本教程实施 Google Places Autocomplete。但是,这只适用于现有的静态定义的文本字段。在我的测试应用程序中,我动态添加了文本字段,用户单击按钮即可添加更多文本字段。
<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 或刚刚添加的输入来处理任何现有输入。
感谢您对此的任何帮助。