我可以在JavaScript的“地图信息”窗口中使用getElementById()吗?
我在谷歌地图上放置了几个标记,每个标记都有一个包含以下内容的信息窗口:我可以在JavaScript的“地图信息”窗口中使用getElementById()吗?,javascript,django,maps,getelementbyid,infowindow,Javascript,Django,Maps,Getelementbyid,Infowindow,我在谷歌地图上放置了几个标记,每个标记都有一个包含以下内容的信息窗口: // Set the content of the infowindow of the marker. var infoContent = '<div id="iw-container" class="gm-style-iw">'+ '<div class="iw-title">'+
// Set the content of the infowindow of the marker.
var infoContent =
'<div id="iw-container" class="gm-style-iw">'+
'<div class="iw-title">'+
'<p>{{place.name}}</p>'+
'</div>'+
// For each photo associated with this place, add it.
'<div class="container-fluid">'+
{% for photo in place.photo_set.all %}
'<div class="row">'+
'<div class="col-md-4">'+
'<hr>'+
'<div class="">'+
// Check whether the attributes have a value and display them.
{% if photo.info != "" and photo.info != None %}
'<p class="iw-info">{{ photo.info }}</p>'+
{% endif %}
{% if photo.year != "" and photo.year != None %}
'<p class="iw-year">{{ photo.year }}</p>'+
{% endif %}
{% if photo.source != "" and photo.source != None %}
'<p class="iw-source">Bron: {{ photo.source }}</p>'+
{% endif %}
'</div>'+
// Display the image with a link to the modal view.
'<div class="iw-image">'+
'<img id="{{ photo.id }}" class="iw-image" src="../static/images/{{ photo.image }}">'+
'</div>'+
'</div>'+
'</div>'+
{% endfor %}
'</div>'+
'</div>';
这是因为每次img变量都为Null
是否可以使用getElementById()访问信息窗口内容?您在哪里调用document.getElementById(“{photo.id}”)
我可以通过在InfoWidow中返回一个Id为的div并在onMarkerClick中调用
document.getElementById()
来完成类似的操作 这可能是因为调用getElementById()时尚未添加infowindow的html代码吗?您是否能够获得任何解决方案。请仅以“新答复”的形式提供问题的答案,您可以在需要时对顶部帖子进行评论以提问。
var img = document.getElementById("{{ photo.id }}");