我想使用JavaScript来使用数组中的值更新文本框值:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
alert(pos['lat'] + ', ' + pos['lng']);
data = pos['lat'] + ', ' + pos['lng'];
document.getElementById("address").value = data.value;
}, function() {
});
}
我的问题是警报正确显示了lat和long坐标,但文本框值更新为“undefined”,这意味着data.value未定义。
我该如何解决这个问题?谢谢!
答案 0 :(得分:0)
试试这个: document.getElementById(" address")。value = data;