从文本区域获取输入

Get input from text area

本文关键字:输入 获取 区域 文本      更新时间:2023-09-26

如何在文本区显示经度和纬度。这段代码似乎有什么问题?谢谢你

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();

您错过了

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

$("#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()'>