我想将图像用于参数。有一个问题,但我不知道在哪里。有人能帮我吗。
这是我的部分;在这部分我不确定它将是占位符还是其他。在那个盒子里它将是字符串。
<div id="floating-panel">
<input id="latlng" type="text" value="38.96374,35.2433">
<input id="img1" type="text" placeholder="Put your picture name">
<input id="submit" type="button" value="Bul">
</div>
这是我的addMarker功能。
function addMarker(location, map, img) {
var markers = [];
var image = img + '.png';
var marker = new google.maps.Marker({
position: location,
map: map,
icon: image
});
google.maps.event.addListener(marker, 'rightclick', function(event) {
marker.setMap(null);
});
markers.push(marker);
}
我将在这里调用函数。
我不知道我应该在哪里使用它,或者它在语法上是否正确。 var imagebox = document.getElementById(&#39; img1&#39;);
function geocodeLatLng(geocoder, map, infowindow)
{
var input = document.getElementById('latlng').value;
var latlngStr = input.split(',', 2);
var latlng = {lat: parseFloat(latlngStr[0]), lng: parseFloat(latlngStr[1])};
geocoder.geocode({'location': latlng}, function(results, status)
{
if (status === 'OK')
{
if (results[1])
{
var imagebox = document.getElementById('img1');
map.setZoom(7);
map.setCenter(latlng);
addMarker(latlng, map, imagebox);
infowindow.setContent(results[1].formatted_address);
infowindow.open(map, marker);
}
else
{
window.alert('No results found');
}
}
else
{
window.alert('Geocoder failed due to: ' + status);
}
});
}
答案 0 :(得分:0)
您发送<input>
代码作为参数,而不是string
。
请参阅以下示例:
function sendValue() {
var i = document.getElementById('img1');
console.log(i);
var i = document.getElementById('img1').value;
console.log(i);
}
&#13;
<input id="img1" type="text" placeholder="Put your picture name">
<input type="button" value="Send" onclick="sendValue()">
&#13;