javascript 谷歌地图中带有 Html 的 InfoWindow
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12703253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
InfoWindow with Html in google maps
提问by user1292656
I am using the following code to create an infowindow for the markers in the map. In the message variable i am sending a string with Html inside it. When i run my application inside the infobox i am getting the string without the Html styling. For example inside the box i see blah blah blah ... Does anyone know how to get the infobox with html styling inside?
我正在使用以下代码为地图中的标记创建信息窗口。在消息变量中,我发送一个带有 Html 的字符串。当我在信息框中运行我的应用程序时,我得到的字符串没有 Html 样式。例如在盒子里面我看到等等等等...有谁知道如何在里面获得带有 html 样式的信息框?
function attachSecretMessage(marker, number) {
var infowindow = new google.maps.InfoWindow(
{ content: message[number],
size: new google.maps.Size(50, 50)
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map1, marker);
});
回答by thomasbabuj
Put all your custom html code in a variable and assign the value to "content" !!!
将所有自定义 html 代码放在一个变量中并将值分配给“内容”!!!
var contentString =
'<div id="content" style="width:400px; background-color:red;">' +
'My Text comes here' +
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString,
maxWidth: 400
});