2017-02-17 58 views
2

如何在引導標籤上應用Google自動填充 - 輸入?

<script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places" type="text/javascript"></script> 
 
<script type="text/javascript"> 
 
    function initialize() { 
 
     var tags_input = document.getElementById('tags'); 
 
     var tag_autocomplete = new google.maps.places.Autocomplete(tags_input); 
 
    } 
 
    google.maps.event.addDomListener(window, 'load', initialize); 
 
</script>
<div class="form-group wish-tags"> 
 
     <label class="col-lg-3 control-label">Already visited:</label> 
 
     <div class="col-lg-8"> 
 
      <input type="text" value="" data-role="tagsinput" id="tags" name="visited_tags" class="form-control"> 
 
     </div> 
 
</div>

是否有可能,谷歌自動填充API的應用上input.i嘗試這種代碼引導標籤,但它不是working..please指導我

+0

什麼去ogle地址? –

+0

Google自動填充API –

+0

將函數調用放入document.ready() –

回答

0

我在我的網站像一個使它這樣的:

<input type="text" value="" data-role="tagsinput" id="tags" name="visited_tags" class="form-control"> 

<script> 
    function initAutocomplete() { 
     var autocomplete = new google.maps.places.Autocomplete(
      /** @type {!HTMLInputElement} */(document.getElementById('tags')), 
      {types: ['geocode']}); 
    } 
</script> 
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places&callback=initAutocomplete" async defer></script> 

很明顯,你必須註冊在谷歌控制檯API密鑰