我正在使用 Google map iframe 在我的网站上生成 map 。 iframe 看起来像这样:
<iframe id="googlemap" width="199" height="199" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?key=KEY&zoom=14&language=nb&q=Møllesvingen+2,0854+OSLO"></iframe>
如果您看到属性 src
,您会看到我想用 %C3%B8
替换的特殊字符“ø”(UTF-8 字节).
我尝试了几个替换函数,但似乎没有任何效果。 这是我现在正在尝试的:
var src;
src = $('#googlemap').attr('src');
src.replace('ø', '%C3%B8');
但它不起作用。希望有人能帮忙。
提前致谢!
最佳答案
您需要添加编码。 试试这个,
src = $('#googlemap').attr('src');
src = encodeURI(src);
$('#googlemap').attr('src', src);
关于javascript - 查找并替换 URL 中的特殊字符 - jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41503104/