我正试图在谷歌地图(v3 API)中收紧一些重复的HTML。
我想将文本HTML放入单个变量中,然后用它来替换代码中重复的字符串。
这是infoWindows的呈现方式:
var locations = [
[39.11009, -120.03169, '<same text html><unique image html>'],
[37.77493, -122.41942, '<same text html><unique image html>'],
[48.85320, -119.30206, '<same text html><unique image html>'],
[48.77734, -121.81320, '<same text html><unique image html>']
];
答案 0 :(得分:0)
创建一个包含每个数组[]共有的html字符串的变量,然后用它来替换常用字符串。正确的语法如下所示:
var Links ='<div class="photo"><a href="whatever.com/">Shop Here</a> | <a href="whatever.com/">Shop There</a></div>';
var locations = [
[39.19, -12.9, Links + '<img width="300" height="239" src="images/img01.jpg"/>'],
[37.73, -12.4, Links + '<img width="300" height="239" src="images/img02.jpg"/>'],
[48.82, -12.3, Links + '<img width="300" height="239" src="images/img03.jpg"/>'],
[48.74, -12.8, Links + '<img width="300" height="239" src="images/img04.jpg"/>'],
[39.37, -12.7, Links + '<img width="300" height="239" src="images/img05.jpg"/>']
];