2015-09-14 112 views
2

如何在textarea中顯示經度和緯度。這段代碼似乎有什麼錯誤?謝謝從文本區域獲取輸入

HTML:

Locations: 
    <select name="ctrTitles" id="ctrTitles"> 
    <option value="1">School</option> 
    <option value="2">Office</option> 

    </select> 

    <textarea name="inputList" id="inputList" cols="50" rows="5" readonly="readonly"></textarea> 
    <input type="button" value="Proses" onclick="clickedAddList()"> 
    <input id="button2" type="button" value="Calculate" onclick="directions(1, false, false, false, false)"> 
<input id='button3' type='button' value='Reset' onclick='startOver()'> 

JS:

var centerLocations = {} 

text1: -9.683075, 124.1241341 - 10.258829, 123.553435 - 10.1965777, 123.5305067, 
    text2: -9.853080, 124.268283 - 10.115900, 123.809843 - 9.874031, 124.249636 
}; 

$('#ctrTitles').change(function() { 
    $("inputList").val(centerLocations["text" + this.value]); 
}).change(); 

回答

2

您在

無緣

應該是

$("#inputList").val(centerLocations["text" + this.value]); 

而且,對象centerLocations未正確定義。 值應該用引號括起來。

應該如下:

var centerLocations = { 
    text1: '-9.683075, 124.1241341 - 10.258829, 123.553435 - 10.1965777, 123.5305067', 
    text2: '-9.853080, 124.268283 - 10.115900, 123.809843 - 9.874031, 124.249636' 
}; 

演示

var centerLocations = { 
 
    text1: '-9.683075, 124.1241341 - 10.258829, 123.553435 - 10.1965777, 123.5305067', 
 
    text2: '-9.853080, 124.268283 - 10.115900, 123.809843 - 9.874031, 124.249636' 
 
}; 
 

 
$('#ctrTitles').change(function() { 
 
    $("#inputList").val(centerLocations["text" + this.value]); 
 
}).change();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> 
 
Locations: 
 
<select name="ctrTitles" id="ctrTitles"> 
 
    <option value="1">School</option> 
 
    <option value="2">Office</option> 
 
</select> 
 

 
<textarea name="inputList" id="inputList" cols="50" rows="5" readonly="readonly"></textarea> 
 
<input type="button" value="Proses" onclick="clickedAddList()"> 
 
<input id="button2" type="button" value="Calculate" onclick="directions(1, false, false, false, false)"> 
 
<input id='button3' type='button' value='Reset' onclick='startOver()'>

+0

耶士,謝謝主人。我能做到 –

+0

@DiaanLast檢查演示 – Tushar

+0

大師,如果我點擊按鈕輸入過程如何顯示標記? –