2011-04-04 80 views
0

問候Overflowers,在InfoWindow.content中插入樣式HTML表格?

我建設使用谷歌地圖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>"; 

回答

3

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

info.setContent(element); 
+0

@Kenned:thank you :)是元素的一個HTML代碼的字符串? – geeko 2011-04-04 09:30:07

+0

在我的情況下,它是一個DOM對象,但AFAIK,你可以使用HTML字符串 http://code.google.com/intl/da-DK/apis/maps/documentation/javascript/reference.html#InfoWindow – 2011-04-04 10:00:54

+0

@ Kenned:表格已添加,但很明顯,沒有特定的樣式:( – geeko 2011-04-06 04:17:34