如何在Html中调用Google map API Javascript的变量?
我知道这是一个非常基本的编程问题,但我想用marker.position作为HTML格式中隐藏输入的值。我试着使用document.getElementById(“position”),但它不起作用,我不知道怎么做。如果有人能帮我,我会非常感激的。以下是我的相关代码行:如何在Html中调用Google map API Javascript的变量?,javascript,html,google-maps,Javascript,Html,Google Maps,我知道这是一个非常基本的编程问题,但我想用marker.position作为HTML格式中隐藏输入的值。我试着使用document.getElementById(“position”),但它不起作用,我不知道怎么做。如果有人能帮我,我会非常感激的。以下是我的相关代码行: function placeMarker(location) { var marker = new google.maps.Marker({ position: location, draggable
function placeMarker(location) {
var marker = new google.maps.Marker({
position: location,
draggable:true,
animation:google.maps.Animation.DROP,
map: map,
icon: image
});
var Makepoint = google.maps.event.addListener(map, 'click', function(event) {
placeMarker(event.latLng);
google.maps.event.removeListener(Makepoint);
});
我的html是
<input class="text" name="here" value="posit" type="hidden">
它正在使用document.getElementById和他的小片段:
document.getElementById("hidden").value = "Your Value";
当然,您的HTML必须是这样的
<input id="hidden" class="text" name="here" value="posit" type="hidden" />
伟大的非常感谢你的回答。现在它工作了没问题,很高兴我能帮忙:)
document.getElementById("hidden").value = marker.position;