谷歌地方API自动完成 - 添加点击事件
问题描述:
我将一个搜索结果追加到google位置javascript api autocomplete中。
I'm appending a Search Results to the google places javascript api autocomplete.
到目前为止,我正在这样做: p>
So far I'm doing this:
var autocomplete;
function initialize() {
var myLatlng = new google.maps.LatLng(40.738793, -73.991402);
autocomplete = new google.maps.places.Autocomplete(document.getElementById('autocomplete'));
}
后来我有这个:
later on I have this:
$('.pac-container').append( '<div class="j-search pac-item-refresh">Search Results</div>' );
$(document.body).on('click', '.pac-container .j-search', function(e) {
console.log('click fired');
});
问题所在?点击事件永远不会触发......
The problem? The click event never fires...
任何想法为什么?我的代码有什么问题?
Any idea why? Anything wrong with my code?
答
看起来, .pac-container
被 Autocomplete
-instance取消。改为使用 mousedown
。
It seems that the click-event for .pac-container
is cancelled by the Autocomplete
-instance. Use mousedown
instead.