gpt4 book ai didi

javascript - 函数未定义javascript onclick

转载 作者:行者123 更新时间:2023-11-30 06:12:44 28 4
gpt4 key购买 nike

<分区>

我是编程新手,所以不要评判我。尝试编写代码来测量经纬度的长度。它显示此错误:

length.html:27 Uncaught ReferenceError: area is not defined at HTMLInputElement.onclick (length.html:27)

<html>
<head></head>
<body>
<script type="module">
import LatLon from 'https://cdn.jsdelivr.net/npm/geodesy@2.2.0/latlon-spherical.min.js';
function area()
{
var la1 = document.getElementById(lat1).value;
var la2 = document.getElementById(lat2).value;
var lo1 = document.getElementById(lon1).value;
var lo2 = document.getElementById(lon2).value;
const p1 = new LatLon(la1, lo1);
const p2 = new LatLon(la2, la2);
const d = p1.distanceTo(p2);
document.write('<br>Length is : ' + d);
}
</script>
<form>
First point<br>
Latitude:&nbsp;
<input type="text" name="lat1" id="lat1"><br>
Longitude:
<input type="text" name="lon1" id="lon1"><br>
Second point<br>
Latitude<input type="text" name="lat2" id="lat2"><br>
Longitude<input type="text" name="lon2" id="lon2"><br>
<input type="button" value="submit" onclick="area()">
</form>
</body>
</html>

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