TL; DR - 有誰知道谷歌地圖Autocomplete的下拉菜單是什麼?谷歌地圖自動完成 - 查找自動完成的HTML作爲jQuery選擇器使用
我在我的網站上使用Google地圖。我想用jQuery提醒用戶從Google給你的自動完成選項中列出的選項中選擇一個選項。如果用戶點擊了輸入,但沒有選擇其中一個選項,我想然後顯示通知。
但是,我似乎無法找到ID彈出選項列表。 (或div或其他HTML。)這些選項的元素中沒有任何內容。
這裏是我的代碼:
HTML
<label for="title" class="form-title">Location</label>
<div class="form-row">
<div class="form-group">
<label>Street Address</label>
<input type="text" id="formatted_address" name="formatted_address">
</div>
<div id="my_map"></div>
</div>
的Javascript
庫
<script src="https://maps.googleapis.com/maps/api/js?key=MYKEY&libraries=places&language=en"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/geocomplete/1.7.0/jquery.geocomplete.min.js"></script>
代碼
$("input#formatted_address").geocomplete({
details: "form",
map: "#my_map" });
謝謝!
你是否包含'jQuery UI'? jQuery沒有自動完成「小部件」。 jQuery UI的[autocomplete](http://api.jqueryui.com/autocomplete/)有一個'select'回調。你可以在這裏使用'event'參數來查找列表項,最後它是ID。不是100%確定,但類似這樣的應該工作:'var selected_item_id = $(event.target).attr('id');' –
@AlmostPitt嘗試我的解決方案 – krishnar
您使用的是Google Maps JavaScript API v3嗎?嵌入式Google地圖? (地圖的代碼是什麼樣的?) – geocodezip