如何将 link 添加到 google 地方 api 提供的下拉菜单(自动完成)?
How do I add a link to the dropdown menu provided by google places api (autocomplete)?
我正在创建一个应用程序,用户可以在其中 post 该地区正在进行的活动。
我有一个使用 google 位置自动完成的输入字段。
<!---- EVENT LOCATION ---->
<div class="form-group">
<label for="location">Event Location</label>
<input name="location" type="text" class="form-control" id="location" placeholder="Hogwarts School, 127 Long Island">
</div>
<script>
var ac = new google.maps.places.Autocomplete(document.getElementById('location'));
ac.addListener('place_changed', function() {
var place = ac.getPlace();
});
</script>
这很好用(see image)
很好,但我想添加 Eventbrite 具有的功能。看看他们有什么 here 。
在下拉菜单的末尾,他们有一个 link 说 "can't find your location?"
我想要那个。知道如何在下拉菜单底部添加 link 吗?
好的,我明白了。稍后会更改它以坚持 jquery 或 javascript。如果您知道更好的方法,请告诉我
<!---- EVENT LOCATION ---->
<div class="form-group">
<label for="location">Event Location</label>
<input name="location" type="text" class="form-control" id="location" placeholder="Hogwarts School, 127 Long Island">
</div>
<script>
var ac = new google.maps.places.Autocomplete(document.getElementById('location'));
ac.addListener('place_changed', function() {
var place = ac.getPlace();
console.log(place.formatted_address);
console.log(place.url);
});
$('#location').on('click', function() {
var picklist = document.getElementsByClassName('pac-container')[0];
var link = picklist.getElementsByTagName('a');
console.log(link.length);
if(link.length == 0) {
var aTag = document.createElement('a');
aTag.setAttribute('href',"http://www.google.com");
aTag.innerHTML = "Can't find address?";
picklist.appendChild(aTag);
}
});
</script>
我正在创建一个应用程序,用户可以在其中 post 该地区正在进行的活动。
我有一个使用 google 位置自动完成的输入字段。
<!---- EVENT LOCATION ---->
<div class="form-group">
<label for="location">Event Location</label>
<input name="location" type="text" class="form-control" id="location" placeholder="Hogwarts School, 127 Long Island">
</div>
<script>
var ac = new google.maps.places.Autocomplete(document.getElementById('location'));
ac.addListener('place_changed', function() {
var place = ac.getPlace();
});
</script>
这很好用(see image)
很好,但我想添加 Eventbrite 具有的功能。看看他们有什么 here 。
在下拉菜单的末尾,他们有一个 link 说 "can't find your location?"
我想要那个。知道如何在下拉菜单底部添加 link 吗?
好的,我明白了。稍后会更改它以坚持 jquery 或 javascript。如果您知道更好的方法,请告诉我
<!---- EVENT LOCATION ---->
<div class="form-group">
<label for="location">Event Location</label>
<input name="location" type="text" class="form-control" id="location" placeholder="Hogwarts School, 127 Long Island">
</div>
<script>
var ac = new google.maps.places.Autocomplete(document.getElementById('location'));
ac.addListener('place_changed', function() {
var place = ac.getPlace();
console.log(place.formatted_address);
console.log(place.url);
});
$('#location').on('click', function() {
var picklist = document.getElementsByClassName('pac-container')[0];
var link = picklist.getElementsByTagName('a');
console.log(link.length);
if(link.length == 0) {
var aTag = document.createElement('a');
aTag.setAttribute('href',"http://www.google.com");
aTag.innerHTML = "Can't find address?";
picklist.appendChild(aTag);
}
});
</script>