将变量放入a href标签

时间:2018-11-19 03:10:48

标签: javascript

我在将变量分配到URL时遇到问题

这是代码

var value = i+1;

 var customPopup = 'Latitude: ' + data.Table[i].Latitude + '</br>Longitude: ' + data.Table[i].Longitude
                + '</br>Station: ' + data.Table[i].StationID + ' </br>Box: ' + data.Table[i].BoxID + '</br>Timestamp: ' + data.Table[i].LocationSend + "<br><a target='_blank' href='/Home/History?DeviceID= ' style='color: #000000'>Click Here For Location History</a></br>";

1 个答案:

答案 0 :(得分:1)

字符串文字可能会有所帮助(使用反引号``):

var value = i+1;

var customPopup = 'Latitude: ' + data.Table[i].Latitude + 
                  '<br/>Longitude: ' + data.Table[i].Longitude + 
                  '<br/>Station: ' + data.Table[i].StationID + 
                  '<br/>Box: ' + data.Table[i].BoxID + 
                  '<br/>Timestamp: ' + data.Table[i].LocationSend + 
                  `<br/><a target='_blank' href='/Home/History?DeviceID=${value}' style='color: #000000'>Click Here For Location History</a><br/>`;