gpt4 book ai didi

javascript - 在文本输入字段中显示纬度和经度

转载 作者:行者123 更新时间:2023-11-29 23:26:41 25 4
gpt4 key购买 nike

如何在输入数字时自动将 , 放入文本输入字段。例如,在文本框中输入 234556443 自动转换为纬度 23.456545 经度 234.5665665

<div class="form-group">
<label for="">Latitude</label>
<input type="number" class="form-control" name="latitude" id="latitude" placeholder="Latitude">
</div>
<div class="form-group">
<label for="">Longitude</label>
<input type="number" name="longitude" class="form-control" id="longitude" placeholder="Longitude">
</div>

最佳答案

您可以使用自定义 javascript 函数并在按键时调用它们来格式化您的输入,我已经为您创建了这些函数,请查看下面的工作示例:

function long( str ){
var longInp = document.getElementById('long');
if(str.length == 2){
longInp.value = str+',';
}
}
function lat( str ){
var latInp = document.getElementById('lat');
if(str.length == 3){
latInp.value = str+',';
}
}
<input type="text" id="long" onkeypress="long(this.value)" placeholder="Longitude"><br>
<input type="text" id="lat" onkeypress="lat(this.value)" placeholder="Latitude">

尝试在经度和纬度中输入一些内容,这将自动在输入中放置一个,

关于javascript - 在文本输入字段中显示纬度和经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48922468/

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