【发布时间】:2015-11-19 17:57:03
【问题描述】:
我是新手,所以提前感谢您的帮助。 我正在设置一个简单的地理位置页面。 目前,当我单击按钮时,会出现一个警报弹出框,说明地理位置设置。
问题 - 我需要将地理位置信息显示在页面本身上,而不是在框中弹出结果。
我被告知我需要使用 appendTo 元素,我尝试了许多不同的方法,但没有任何反应。
这是当前脚本:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Geolocation</title>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.
js"</script>
<section>
<script>
$(document).ready(function() {
$('#startGeo').click(checkLocation);
function checkLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(getLocation,
locationFail);
}
else {
document.write('You do not have geolocation');
}
}
function getLocation(position) {
var latitude = position.coords.latitute;
var longitude = position.coords.longitude;
var accuracy = position.coords.accuracy;
var timestamp = position.coords.timestamp;
alert('latitude: ' + latitude + 'longitude: ' + longitude +
'accuracy: ' + accuracy + 'timestamp: ' + timestamp);
}
function locationFail() {
document.write('We did not get your location. Please check your
settings.')
}
});
</script>
</head>
<body>
<button id="startGeo">Click here to check your geolocation
abilities</button>
</body>
</html>
【问题讨论】:
标签: javascript jquery popup append appendto