首页 > 解决方案 > 在 HTML 中,如何将变量附加到 url?

问题描述

我在表格中有一个地址列表,我想要它,这样如果你点击地址,你会得到一个指向那个地方的谷歌地图链接。这是我的尝试;<a ...> 是我尝试得到它但最终失败了。如果 (40,-70) 是纬度/经度,我想要一个示例谷歌地图页面将您带到https://www.google.com/maps/search/?api=1&query=40%2C-70以便它实际上显示了字段中描述的纬度/经度。

<table>
<tr>
  <th>Name</th>
  <th>Address</th>
  <th>Zip Code</th>
</tr>
<tbody>
  {% for pl in markers %}
  <tr>
    <td>{{pl.fields.name}}</td>
    <td><a href="https://www.google.com/maps/search/?api=1&query="pl.fields.latitude"%2C"pl.fields.longitude">{{pl.fields.address}}</a></td>
    <td>{{pl.fields.zip}}</td>
  </tr>
  {% endfor %}
</tbody>
这是输出的内容:

在此处输入图像描述

这些链接应该指向 google maps API 的纬度/经度,但现在它不起作用。我该怎么做呢?

标签: html

解决方案


额外的引号把它扔掉了。

<table>
<tr>
  <th>Name</th>
  <th>Address</th>
  <th>Zip Code</th>
</tr>
<tbody>
  {% for pl in markers %}
  <tr>
    <td>{{pl.fields.name}}</td>
<td><a href="https://www.google.com/maps/search/?api=1&query={{pl.fields.latitude}},{{pl.fields.longitude}}">{{pl.fields.address}}</a></td>
    <td>{{pl.fields.zip}}</td>
  </tr>
  {% endfor %}
</tbody>

推荐阅读