gpt4 book ai didi

javascript - 从文本区域获取输入

转载 作者:行者123 更新时间:2023-11-27 23:39:04 25 4
gpt4 key购买 nike

如何在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();

最佳答案

你错过了 #

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

关于javascript - 从文本区域获取输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32557142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com