JavaScript 重定向网页时不将值视为字符串
JavaScript not treating value as string when redirecting web-page
我有一个按钮选择,当按下这些按钮时导航到 URL,这个网页实际上嵌入到一个程序中,导航到 URL 作为程序使用的参数,因此 URL 实际上是不同字符串的选择。例如:
'030056310001''039026320003''340003253OPP'
有些参数有字母字符,有些只有数字,有些只有小于 7 的数字,因此被视为 octal numbers
我如何将所有值视为字符串以便它们导航到特定 URI?
var content = '<button type="button" onclick="location.href=' + actual_JSON[key].location_code + '">Learn More</button>';
上面的代码显示了按钮的详细信息,下面是完整的代码,我们将不胜感激。
for (var key in actual_JSON) {
var infowindow = new google.maps.InfoWindow();
var content = '<h3> Name: ' + actual_JSON[key].description + '</h3> <p> ID: ' + actual_JSON[key].location_code + '</p><p> Bearing: ' + actual_JSON[key].bearing + '<p> <button type="button" onclick="location.href=' + actual_JSON[key].location_code + '">Learn More</button>';
console.log(actual_JSON[key].location_code);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(actual_JSON[key].latitude, actual_JSON[key].longitude),
map: maps,
title: actual_JSON[key].description,
});
google.maps.event.addListener(marker, 'click', (function (marker, content, infowindow) {
return function () {
infowindow.setContent(content);
infowindow.open(map, marker);
};
})(marker, content, infowindow));
markers.push(marker);
}
}
根据 Satpal 的建议 -
将 location_code 括在引号中,即 onclick="location.href=\'' + actual_JSON[key].location_code + '\'"
我会把这个问题留给可能需要的人。
我有一个按钮选择,当按下这些按钮时导航到 URL,这个网页实际上嵌入到一个程序中,导航到 URL 作为程序使用的参数,因此 URL 实际上是不同字符串的选择。例如:
'030056310001''039026320003''340003253OPP'
有些参数有字母字符,有些只有数字,有些只有小于 7 的数字,因此被视为 octal numbers
我如何将所有值视为字符串以便它们导航到特定 URI?
var content = '<button type="button" onclick="location.href=' + actual_JSON[key].location_code + '">Learn More</button>';
上面的代码显示了按钮的详细信息,下面是完整的代码,我们将不胜感激。
for (var key in actual_JSON) {
var infowindow = new google.maps.InfoWindow();
var content = '<h3> Name: ' + actual_JSON[key].description + '</h3> <p> ID: ' + actual_JSON[key].location_code + '</p><p> Bearing: ' + actual_JSON[key].bearing + '<p> <button type="button" onclick="location.href=' + actual_JSON[key].location_code + '">Learn More</button>';
console.log(actual_JSON[key].location_code);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(actual_JSON[key].latitude, actual_JSON[key].longitude),
map: maps,
title: actual_JSON[key].description,
});
google.maps.event.addListener(marker, 'click', (function (marker, content, infowindow) {
return function () {
infowindow.setContent(content);
infowindow.open(map, marker);
};
})(marker, content, infowindow));
markers.push(marker);
}
}
根据 Satpal 的建议 -
将 location_code 括在引号中,即 onclick="location.href=\'' + actual_JSON[key].location_code + '\'"
我会把这个问题留给可能需要的人。