var circle = new google.maps.Circle({
center: latLng,
radius: radius,
strokeColor: "#FF0000",
strokeOpacity: 0.5,
strokeWeight: 1,
fillColor: "#FF0000",
fillOpacity: 0.2
});
circle.setMap(map);
map.fitBounds(circle.getBounds());
jQuery('#area').change(function() {
radius = jQuery('#area').val();
var newLatLng = marker.getPosition();
circle.setMap(null);
var circle = new google.maps.Circle({
center: latLng,
radius: radius,
strokeColor: "#FF0000",
strokeOpacity: 0.5,
strokeWeight: 1,
fillColor: "#FF0000",
fillOpacity: 0.2
});
circle.setMap(map);
map.fitBounds(circle.getBounds());
});
circle
後undefined是在jQuery('#area').change()
之外定義的,但是當我嘗試從jQuery('#area').change()
函數內部訪問它,我得到一個未定義的錯誤。爲什麼是這樣?可變jQuery的變化
同意jimbojw在這裏是一個小提琴演示:http://jsfiddle.net/Pks4R/ –
+1很好的答案。解釋器將範圍內的所有變量聲明視爲該範圍中的第一行。 –