我想在单击我的下拉选项之一时更改 Google 地图脚本 src,因为在我的页面上搜索邮政编码时遇到问题。为了获得正确的结果,我相信我需要在 src url 中使用 Google 的区域本地化“®ion=”。(https://developers.google.com/maps/documentation/javascript/basics#Localization)
我已经在<head>
标签中加载了我的 google maps api:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
我创建了一个下拉列表
<select id="country">
<option value="sel">Select</option>
<option value="DK">Denmark</option>
<option value="NL">Netherlands</option>
<option value="SE">Sweden</option>
</select>
我希望在单击其中一个选项时更改 google maps 脚本 src。
例如:如果我单击丹麦,则 src 将更改为:
http://maps.googleapis.com/maps/api/js?sensor=false®ion=DK
我已经通过查看这个Dynamically change the src of a script 标签尝试了一些东西, 但我仍然不知道如何使它工作。
目前我有这个:
$('#country option').click(function(e) {
e.preventDefault();
var region = $(this).attr('value');
var url = 'http://maps.googleapis.com/maps/api/js?sensor=false®ion=' + region;
});
当谈到 jQuery 和 javascript 时,我真的是新手,所以我想也许我可以在这里得到一些帮助。