试图使用两个插入文本框id来形成谷歌地图的地址。我可以使用一个Id,但是县城没有影响。
<div id="map" style="width: 400px; height: 300px;"></div>
</br>
<input type="text" id="search"> Street
</br>
<input type="text" id="search2"> County
</br>
<input type="button" onclick="geocode();" value="Go">
function geocode () {
geocoder.geocode({
'address': document.getElementById('search','search2').value
},
getElementById
只返回一个元素,所以你不能用它一次访问两个元素。
一次访问一个元素,我猜您希望将这些值放在一起,并在它们之间使用分隔符,如空格:
'address': document.getElementById('search').value + ' ' + document.getElementById('search2').value
传递两个id是不可能的。您需要这样的内容:
'address': document.getElementById('search').value + ', ' + document.getElementById('search').value