The problem is that codeAddress()
doesn't have enough scope to be callable from the button.(问题是codeAddress()
没有足够的范围可以从按钮调用。)
You must declare it outside the callback to ready()
:(您必须在回调之前将其声明为ready()
:)
function codeAddress() {
var address = document.getElementById("formatedAddress").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
}
});
}
$(document).ready(function(){
// Do stuff here, including _calling_ codeAddress(), but not _defining_ it!
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…