2016-03-16 13 views
-1

我正試圖分配我的下拉菜單的功能,所以當你點擊所選的縣時,它將在該縣上放火。我已經寫下了我可以在下面通過研究,因爲我是所有這些的新手,但我不知道如何將它們連接在一起。 我知道我沒有附加googlemaps,但我在我的整個頁面中,這只是這一節,我試圖鏈接在一起有麻煩。嘗試將功能分配給我的下拉菜單中的邊界

<!doctype html> 
    <html> 
    <head> 

<script type="text/javascript"> 

document.getElementById('counties').addEventListener('click', function(e) {alert(this.value); e.preventDefault();}, false); 
$('bedfordshire').click(function(){ 
alert(this.value); 
}); 
$('buckinghamshire').click(function(){ 
alert(this.value); 
}); 
$('cambridgeshire').click(function(){ 
alert(this.value); 
}); 
$('hertfordshire').click(function(){ 
alert(this.value); 
}); 
$('northamptonshire').click(function(){ 
alert(this.value); 
}); 

//bedfordshire 
bounds = new google.maps.LatLngBounds(); 
bounds.extend(new google.maps.LatLng(52.33, -0.05)); 
    bounds.extend(new google.maps.LatLng(51.8, -0.8)); 
map.fitBounds(bounds); 

//buckinghamshire 
bounds = new google.maps.LatLngBounds(); 
bounds.extend(new google.maps.LatLng(52.21, -0.33)); 
bounds.extend(new google.maps.LatLng(51.47, -1.33)); 
map.fitBounds(bounds); 

//cambridgeshire 
bounds = new google.maps.LatLngBounds(); 
bounds.extend(new google.maps.LatLng(52.75, -0.55)); 
bounds.extend(new google.maps.LatLng(51.99, -0.53)); 
map.fitBounds(bounds); 

//hertfordshire 
bounds = new google.maps.LatLngBounds(); 
bounds.extend(new google.maps.LatLng(52.09, -0.35)); 
bounds.extend(new google.maps.LatLng(51.59, -0.80)); 
map.fitBounds(bounds); 

//northamptonshire 
bounds = new google.maps.LatLngBounds(); 
bounds.extend(new google.maps.LatLng(52.67, -0.33)); 
bounds.extend(new google.maps.LatLng(51.94, -1.35)); 
map.fitBounds(bounds); 


</script> 

</head> 
<body> 
<select id="Counties" > 
<option value="">Select County</option> 
    <option value="bedfordshire">Bedfordshire</option> 
    <option value="buckinghamshire">Buckinghamshire</option> 
    <option value="cambridgeshire">Cambridgeshire</option>      
    <option value="hertfordshire">Hertfordshire</option> 
    <option value="northamptonshire">Northamptonshire</option> 
</select> 

</body> 
</html> 
+0

[從選擇下拉菜單更新谷歌地圖(http://stackoverflow.com/questions/5484419/update-google-map-from-select-dropdown-menu) – geocodezip

+0

的javascript/HTML是可能的重複區分大小寫,「縣」與「縣」不一樣。 ('document.getElementById('counties')';不會找到'