在Javascript中引用图像

Referencing Images within Javascript

本文关键字:图像 引用 Javascript      更新时间:2023-09-26

我有一个javascript地图我正在使用,我试图添加一个图像到工具提示

代码如下:

var shardicon = L.Icon.extend({
        iconUrl: 'images/A.png',
        shadowUrl: '',
        iconSize: new L.Point(20, 30),
        iconAnchor: new L.Point(10, 15),
        popupAnchor: new L.Point(-0, -20)
    });
    var shard = new shardicon()
    var marker7 = new L.Marker(new L.LatLng(51.504409, -0.086335), {icon: shard})
    marker7.bindPopup("<h1>The Shard</h1>");

当我尝试将图像引用添加到HTML位(碎片位)时,它关闭"引号"并中断。

你知道我该怎么做吗?

提前感谢!

在Javascript中,您可以使用双引号和单引号,使用一个为JS解释器分隔外部字符串,另一个为HTML分隔,如下所示:

marker7.bindPopup("<h1>The Shard<img src='images/A.png'></h1>");

或者,也可以这样做:

marker7.bindPopup('<h1>The Shard<img src="images/A.png"></h1>');