我有这个问题,ajax 上有一个函数需要 lat 和 lng 变量,所以函数 test(lat,lng)...
这是 HTML 简单代码:
<fieldset>
<legend>Serveis de geocodificació</legend>
Latitud:<br><input type="text" id="lat" value="42.3600077"/><br>
Longitud:<br><input type="text" id="lng" value="1.4579696"/><br>
<input type="button" value="Veure dades" onclick=primerSelect()/>
<input type="button" value="Veure coordenades"/><br>
Carrer:<br><input type="text" id="car"/><br>
Ciutat:<br><input type="text" id="ciu"/><br>
Pais:<br><input type="text" id="pai"/><br>
CP:<br><input type="text" id="cod"/><br>
</fieldset>
所以,问题出在onclick上,我如何获取id的经纬度值?并将其放入onclick函数中?像这样:
onclick=primerSelect(id lat.value, id lng.value)
有人可以帮我吗?
最佳答案
我不会使用onclick
,而是使用事件监听器。通过这种方式,您的代码会更容易使用。无论如何,你可以使用
onclick="primerSelect(document.getElementById('lat').value,
document.getElementById('lng').value)"
关于javascript - 如何获取输入的值并将其放入 onclick 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23302435/