【问题标题】:Inserting Styled HTML Table inside InfoWindow.content?在 InfoWindow.content 中插入样式化的 HTML 表格?
【发布时间】:2011-04-04 07:28:38
【问题描述】:

问候溢出者,

我正在使用 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>";

【问题讨论】:

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


    【解决方案1】:

    你是如此接近,你需要使用 info.setContent() 代替。

    info.setContent(element);
    

    【讨论】:

    • 在我的例子中,它是一个 dom 对象,但 AFAIK 你可以使用 HTML 字符串 code.google.com/intl/da-DK/apis/maps/documentation/javascript/…
    • @Kenned:表格已添加,但很简单,没有特定样式:(
    • 根据它应该适用的文档,您确定没有任何干扰吗?我在哪里使用它我的风格确实适用。
    • 肯尼德:我的错。我使用 table.colorful 作为表格类而不是彩色的。非常感谢!
    • 不客气,我知道对问题视而不见
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 2013-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多