javascript - 在 InfoWindow.content 中插入样式化的 HTML 表格?

标签 javascript html css google-maps-api-3

问候溢出者,

我正在使用 Google Maps API 构建一些工具
我想插入一些样式化的 HTML 表格而不是纯文本
不过,我没有成功。那么,有什么想法吗?谢谢!

<style type="text/css">
    html { height: 100% }
    body { height: 100%; margin: 0px; padding: 0px }
    table.colorful {
        font-family: verdana, arial, sans-serif;
        font-size: 11px;
        color: #333333;
        border-width: 1px;
        border-color: #999999;
        border-collapse: collapse;
    }
    table.colorful th {
        background: #b5cfd2 url('blueCell.jpg');
        border-width: 1px;
        padding: 8px;
        border-style: solid;
        border-color: #999999;
    }
    table.colorful td {
        background: #dcddc0 url('greenCell.jpg');
        border-width: 1px;
        padding: 8px;
        border-style: solid;
        border-color: #999999;
    }
    #mapCanvas { height: 100% }
</style>

这里:

var info = new google.maps.InfoWindow({
                position: dcs[i].coord,
                content: ""
            });

            info.content = "<table class=\"table.colorful\"><tr><th>Server</th><th>Site</th><th>IP</th><th>Services</th></tr>"

            for(var j in dcs[i].servers) {
                info.content += "<tr><td><b>" + dcs[i].servers[j].name + "</b></td><td>" + dcs[i].servers[j].site + "</td><td>" + dcs[i].servers[j].ip + "</td><td>" + dcs[i].servers[j].services + "</td></tr>";
            }

            info.content += "</table>";

最佳答案

你太接近了,你需要改用 info.setContent()。

info.setContent(element);

关于javascript - 在 InfoWindow.content 中插入样式化的 HTML 表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5535676/

相关文章:

html - 多行布局中的 Flexbox 等高行

javascript - 动态更改自定义按钮上的文本

javascript - settimeout 后返回到多步最小形式的第一步

javascript - Node.js 中的图像拖放和上传

javascript - 为什么循环属性不适用于我的第二个动画?

css - 设置高度 : 100% on my label element doesn't work

javascript - 使用Flow时如何向Error对象添加调试信息?

javascript - React,在包含相同组件的路由之间导航时处理获取的最佳方法

css - Div 显示在页面中央,背景延伸

javascript - 未为直接子元素返回元素高度