简体   繁体   English

如何使用数组中的值更新文本框值?

[英]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! 谢谢!

  • Note: I can't provide a code snippet for geolocation on stackoverflow it seems? 注意:我似乎无法在stackoverflow上提供用于地理位置的代码段? * *

试试这个:document.getElementById(“ address”)。value = data;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从表中的文本框中获取值并使用javascript更新它 - how to get the value from textbox in table and update it using javascript 使用文本框中的值更新javascript数组的值 - Update a javascript array's values with values from a textbox 如何使用javascript设置文本框的值 - how do i set value of a textbox using javascript 如何将值从 JavaScript 中的函数返回到 HTML 中的文本框 - How do I return a value from a function in JavaScript to a textbox in HTML 我如何更新状态以使用 array.map 函数更新数组内对象的值 - how do i update state in react for updating the value of an object inside an array using array.map function 如何在Express.js中使用值数组和预准备语句更新MySQL中的表? - How do I update a table in MySQL using an array of values and a prepared statement in Express.js? 如何使用jQuery将文本框值存储在数组中? - how to store textbox values in array using jquery? 如何通过将值与另一个数组匹配,从数组中正确找到 object 中的值 - How do I correctly find a value in an object from an array, by matching it to another array with the values 如何从数组中获取值? - How do I get values from an array? 如何使用JavaScript从文本框中检索数据? - How do I retrieve data from a textbox using JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM