2014-04-25 80 views
0

我有這個問題,對阿賈克斯需要緯度和經度變量的函數,所以功能測試(緯度,經度)...如何讓輸入的值,並把它變成一個onclick

這在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) 

任何人都可以幫助我嗎?

回答

3

我不會使用onclick,而是使用事件偵聽器。你的代碼會更容易使用這種方式。在任何情況下,你可以使用

onclick="primerSelect(document.getElementById('lat').value, 
    document.getElementById('lng').value)" 
+0

+1 - 但是,請使用一個事件監聽器!查看充滿內聯JS的頁面會導致輕微的瘋狂。 – tymeJV

+0

哦耶!它運作良好,thx爆炸!有一個愉快的週末 – jvillegas

+0

我創建了一個新問題,也許你可以幫助我呢? thx所有 – jvillegas

0

你可以做這樣的事情:

function primerSelect(){ 
    var lat = document.getElementById('lat').value; 
    var lng = document.getElementById('lng').value; 

    // Here goes your code... 
} 
相關問題