更正用于连接的Javascript语法

时间:2013-07-23 18:14:25

标签: javascript jquery concatenation foursquare

我正在尝试使用foursquare API提取位置,而且似乎没有正确编写语法。

 address = '<p><a href="http://maps.google.com/?q="' + 
 venues.location.address + '">' + 
 venues.location.address + '</p>';

虽然这不会引发错误,但会产生以下代码:

<a href="http://maps.google.com/?q=">Correct Business Name</a>

重点是,谷歌地图使用的查询字符串缺失,并且在链接文本中正确显示。我的串联/语法错在哪里?

1 个答案:

答案 0 :(得分:0)

试试这个:

address = '<p>' +
    '<a href="http://maps.google.com/?q=' +
    encodeURIComponent(venues.location.address) +
    '">' +
    venues.location.address +
    '</p>';