【问题标题】:How do I add a link to the dropdown menu provided by google places api (autocomplete)?如何添加指向 google places api(自动完成)提供的下拉菜单的链接?
【发布时间】:2016-12-17 04:23:56
【问题描述】:

我正在创建一个应用程序,用户可以在其中发布该地区正在发生的事件。

我有一个使用谷歌地方自动完成的输入字段。

      <!---- 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

在他们的下拉菜单末尾,他们有一个链接说“找不到你的位置?”

我想要那个。关于如何将链接添加到下拉菜单底部的任何想法?

【问题讨论】:

    标签: jquery google-places-api google-places


    【解决方案1】:

    好吧,我想通了。稍后将更改它以坚持使用 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>
    

    【讨论】:

      猜你喜欢
      • 2016-10-27
      • 2019-08-21
      • 2020-08-20
      • 2011-01-30
      • 2018-11-09
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2013-10-10
      相关资源
      最近更新 更多