Javascript 我怎样才能有一个url超链接?
我怎样才能将url链接到一个网站,而不只是显示为未链接的文本?我已经在下面粘贴了json和点击脚本!我有我想在点击时显示的信息,我希望信息“描述”是一个实时链接。我是初学者,对语法感到抱歉:/Javascript 我怎样才能有一个url超链接?,javascript,html,Javascript,Html,我怎样才能将url链接到一个网站,而不只是显示为未链接的文本?我已经在下面粘贴了json和点击脚本!我有我想在点击时显示的信息,我希望信息“描述”是一个实时链接。我是初学者,对语法感到抱歉:/ json: { "features": [ { "type": "Feature", "properties": { "title": "Si
json:
{
"features": [
{
"type": "Feature",
"properties": {
"title": "Simply Pure",
"description": "simplypure.com"
},
"geometry": {
"coordinates": [-105.0113291,39.7619213,0],
"type": "Point"
}
},
],
"type": "FeatureCollection"
}
这是剧本:
<script>
map.on('click', function (e) {
var features = map.queryRenderedFeatures(e.point, {
layers: ['test-two'] // replace this with the name of the layer
});
if (!features.length) {
return;
}
var feature = features[0];
var popup = new mapboxgl.Popup({ offset: [0, -15] })
.setLngLat(feature.geometry.coordinates)
.setHTML(
'<h3>' +
feature.properties.title +
'</h3><p>' +
feature.properties.description +
'</p>'
)
.setLngLat(feature.geometry.coordinates)
.addTo(map);
});
</script>
地图上('点击')功能(e){
var features=map.queryRenderedFeatures(即点{
层:['test-two']//将其替换为层的名称
});
如果(!features.length){
返回;
}
变量特征=特征[0];
var popup=new mapboxgl.popup({offset:[0,-15]})
.setLngLat(特征、几何、坐标)
.setHTML(
'' +
feature.properties.title+
“”+
feature.properties.description+
“”
)
.setLngLat(特征、几何、坐标)
.addTo(地图);
});
您需要使用HTML
地图上('点击')功能(e){
var features=map.queryRenderedFeatures(即点{
层:['test-two']//将其替换为层的名称
});
如果(!features.length){
返回;
}
变量特征=特征[0];
var popup=new mapboxgl.popup({offset:[0,-15]})
.setLngLat(特征、几何、坐标)
.setHTML(
'' +
feature.properties.title+
''
)
.setLngLat(特征、几何、坐标)
.addTo(地图);
});
errr,与json无关。。。。。如果你想要一个链接,它需要是一个
<script>
map.on('click', function (e) {
var features = map.queryRenderedFeatures(e.point, {
layers: ['test-two'] // replace this with the name of the layer
});
if (!features.length) {
return;
}
var feature = features[0];
var popup = new mapboxgl.Popup({ offset: [0, -15] })
.setLngLat(feature.geometry.coordinates)
.setHTML(
'<h3>' +
feature.properties.title +
'</h3><a href="' + feature.properties.description + '">' +
feature.properties.description +
'</a>'
)
.setLngLat(feature.geometry.coordinates)
.addTo(map);
});
</script>