[英]How do I update a textbox value using values from an array?
I'd like to use JavaScript to update a textbox value using values from an array: 我想使用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() {
});
}
My problem is that the alert displays the lat and long coordinates correctly, but the textbox value gets updated to "undefined", meaning data.value is undefined. 我的问题是警报可以正确显示纬度和经度坐标,但是文本框值已更新为“未定义”,这意味着data.value是未定义的。
How can I fix this? 我怎样才能解决这个问题? Thanks! 谢谢!
试试这个:document.getElementById(“ address”)。value = data;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.