Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在document.getElementById类型函数中使用两个id。_Javascript_Html - Fatal编程技术网

Javascript 如何在document.getElementById类型函数中使用两个id。

Javascript 如何在document.getElementById类型函数中使用两个id。,javascript,html,Javascript,Html,尝试使用两个插入文本框ID来形成google地图的地址。我可以用一个身份证,但县不起作用 <div id="map" style="width: 400px; height: 300px;"></div> </br> <input type="text" id="search"> Street </br> <input type="text" id="search2"> County </br> <inp

尝试使用两个插入文本框ID来形成google地图的地址。我可以用一个身份证,但县不起作用

<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
    }, 

无法传递2个ID。你需要像这样的东西:

'address': document.getElementById('search').value + ', ' + document.getElementById('search').value
getElementById只返回一个元素,因此不能使用它同时访问两个元素

一次访问一个元素,我假设您希望将值与它们之间的分隔符放在一起,如空格:

'address': document.getElementById('search').value + ' ' + document.getElementById('search2').value

getElementById返回单个元素,不能接受两个参数。你为什么想要这个?我正在尝试为用户创建一个简单的表单。我最终会将县输入更改为下拉列表。