gpt4 book ai didi

javascript - 标记窗口信息上的链接

转载 作者:行者123 更新时间:2023-11-30 06:24:58 25 4
gpt4 key购买 nike

我有一张谷歌地图,我想在标记的窗口信息上添加一个链接。标记是从mysql数据库生成的。

我试图理解我恢复的代码,但我无法在信息窗口中添加链接。

(你不能运行代码)

var infoWindow = new google.maps.InfoWindow;

// Change this depending on the name of your PHP or XML file
downloadUrl('xml.php', function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName('marker');
Array.prototype.forEach.call(markers, function(markerElem) { //loop
var id = markerElem.getAttribute('id'); //stock id variable
var name = markerElem.getAttribute('name'); //stock name variable
var address = markerElem.getAttribute('address'); //stock address variable
var type = markerElem.getAttribute('type'); //stock type variable
var point = new google.maps.LatLng( //Recovered the coordinates for the markers
parseFloat(markerElem.getAttribute('lat')),
parseFloat(markerElem.getAttribute('lng')));

var infowincontent = document.createElement('div'); //Displays name in strong
var strong = document.createElement('strong');
strong.textContent = name
infowincontent.appendChild(strong);

infowincontent.appendChild(document.createElement('br')); //Back to the line

var text = document.createElement('text'); //Displays type
text.textContent = type
infowincontent.appendChild(text);

var text = document.createElement('text'); //Displays id (Irrelevant)
text.textContent = id
infowincontent.appendChild(text);

infowincontent.appendChild(document.createElement('br')); //Back to the line

var text = document.createElement('text'); //Displays address
text.textContent = address
infowincontent.appendChild(text);

var icon = customLabel[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
label: icon.label
});
marker.addListener('click', function() {
infoWindow.setContent(infowincontent);
infoWindow.open(map, marker);
});
});
});
}

结果照片:

Demonstration

我想要 strong 文本,它显示的名称是一个链接到一个 url "bottle.php?id="equal variable "id"which is already import

我希望我表达得很好,提前谢谢你

最佳答案

我最终找到了解决方案,这里有一个链接:

          var a = document.createElement('a');
a.textContent = "Visit this store"
a.href = "/bottle.php?id=" + id;
infowincontent.appendChild(a);

关于javascript - 标记窗口信息上的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51031769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com