我目前正在研究谷歌地圖,我有這段代碼將一些內容加載到CMS的標記中。谷歌地圖,格式化一個字符串。 (去除撇號)
function showMarker(index) {
infowindow.setContent("<div class=\"map_marker\">" + markerData[index].content + "</div>");
infowindow.open(map, markers[index]);
map.panTo(markers[index].getPosition());
showAttractionInfo(index);
}
然而,眼下的問題是,如果一個撇號或報價被放在通過CMS是將打破地圖,它不會顯示。
我需要一種方式來格式化markerData[index].content
,然後將其放入地圖中,刪除撇號和引號。
我試過使用replace
,但它根本不適用於我。 有什麼建議嗎?
編輯:
我試過到目前爲止這些解決方案:
infowindow.setContent("<div class=\"map_marker\">" + markerData[index].content.replace(/'/g, '') + "</div>");
var description = markerData[index].content;
description.replace(/'/g, '');
infowindow.setContent("<div class=\"map_marker\">" + description + "</div>");
var description = markerData[index].content;
description.replace("'", "");
infowindow.setContent("<div class=\"map_marker\">" + markerData[index].content + "</div>");
var description = markerData[index].content;
description.replace("'", "'");
infowindow.setContent("<div class=\"map_marker\">" + markerData[index].content + "</div>");
var description = markerData[index].content;
description.replace(/'/g, ''');
infowindow.setContent("<div class=\"map_marker\">" + markerData[index].content + "</div>");
這裏的標誌DATAS的一個示例(帶撇號)
72德里門的路,比爾登,格拉斯哥,G61 2RH
請發佈您嘗試過的代碼沒有用 - 可能只是一個錯字或簡單的錯誤。 – 2014-09-26 10:11:14
發佈'markerData [index] .content'的示例,以便我們知道您在說什麼。 – Andy 2014-09-26 10:14:55
[你可以使用一些正則表達式btw](http://jsfiddle.net/z92hano6/)。 – Andy 2014-09-26 10:21:19