我在Google地图脚本中有以下代码......
<a class='btn btn-modal' data-target='popup.html'>Go</a>
在脚本之外,链接工作并运行函数$('.btn-modal').click(function() {
(在页面上),但在infoWindowHtml中却没有。
任何人都知道为什么你不能从护目镜地图中在我的页面上运行脚本?
脚本我希望在Google地图所在的页面顶部运行...
$(document).ready(function () {
// Support for AJAX loaded modal window
$('.btn-modal').click(function () {
$.get($(this).attr('data-target'), function (data) {
$('#modal').html(data);
$('#modal').modal('show');
}, 'html');
});
});
Google地图摘录显示链接
map = new google.maps.Map(document.getElementById("map"), options);
// Create an Array for the Markers
var markers = [];
var latLng = new google.maps.LatLng(#local.poiLat()#, #local.poi()#);
var iconImg = '/assets/images/pin-50.png';
var marker = new google.maps.Marker({
icon: iconImg,
draggable: true,
position: latLng,
title: '#left(local.poiTxt(),60)#'
});
// Action Listener for the Marker
google.maps.event.addListener(marker, "click", function (event) {
var area = this.get('location');
var infoWindowHtml = "<a class='btn btn-modal' data-target='popup.html'>Go</a>";
infoWindow.setContent(infoWindowHtml);
infoWindow.open(map, this);
});
答案 0 :(得分:2)
infowindow不是加载DOM的一部分......所以你需要使用on
而不是click
:
$(document).on('click','.btn-modal',function() {
document
是加载时出现的父元素 - 可能是地图id
的{{1}} ...所以
div