函数在控制台中显示“未定义”
Function shows `undefined` in console
我的代码:
function geocodeAddress(address){
var geocoder = new google.maps.Geocoder();
geocoder.geocode(
{
'address':address
},
function(results,status){
if(status===google.maps.GeocoderStatus.OK){
var resultsObj = results[0].geometry;
var resultsLocationObj = resultsObj['location'];
var lat = resultsLocationObj['k'];
var lon = resultsLocationObj['D'];
var coordinatesObj = {
address : address,
latitude : lat,
longitude : lon
};
return coordinatesObj;
}
}
);
}
$(document).ready(function(){
function initialize(){
$('#save-address').click(
function saveAddress(){
var addressText = $('#address').val();
console.log(geocodeAddress(addressText));
}
);
}
google.maps.event.addDomListener(window, 'load', initialize);
})
函数运行时,将有两件事打印到控制台:
-
undefined at line XXXX
,其中XXXX
是第二条线console.log()
. coordinatesObj
的值(包含地址、纬度和经度的对象)
我希望第二个console.log()
显示coordinatesObj
的值。
我该怎么办?
如果没有看到您的标记,我们无法确定发生了什么,但从您显示的代码来看 - 我怀疑没有带有"地址"的 HTMLInputElement 元素。
$("#invalidId").val(); // returns `undefined`
相关文章:
- 敲除jsobservable显示未定义的值
- 得到"未定义不是函数“;使用显示原型图案时出错
- Highcharts工具提示不显示corrosconding文本值,而是显示'未定义'
- 使用eval()定义变量显示未定义的错误
- Meteor js-控制台显示'未定义'即使返回结果
- wysihtml5命令显示为未定义
- Json显示来自网站的数据显示仅未定义
- 为什么“;未定义的“;以棱角分明的js显示
- 打字稿显示不能设置未定义的属性,如何解决
- 对象的属性显示为未定义
- JS方法显示了未定义的简单示例
- 当使用多个false时,Select2显示未定义
- AngularJS ng repeat显示原型函数未定义
- 函数在控制台中显示“未定义”
- HTML 对象在使用 ContentPlaceHolder 时在 Javascript 中显示为未定义
- 当我编写脚本时,它显示引用错误:未定义宽度
- 对象属性在控制台.log中显示为未定义
- 当我编写脚本时,它显示类型错误:menuLi[i] 未定义
- 未定义显示在选项中
- 引用错误:未定义显示