[英]Pass alert value into input field
我有一個提醒我當前經度和緯度的功能。 但是,我不想提醒此值。 相反,我希望在單擊“平移”后將此值輸入到位置文本框中
<html>
<script>
function getPosition() {
var options = {
enableHighAccuracy: true,
maximumAge: 3600000
}
var watchID = navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
function onSuccess(position) {
alert('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n');
};
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
}
</script>
<body>
<div data-role="page" data-theme="b">
<div data-role="header">
<h1>Test</h1>
</div>
</div>
<br>
<br>
<label for="Location">Location:</label>
<button onclick = "getPosition()" id = "getPosition">PAN</button>
<input type="text" name="Location" id="location">
<br>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
在成功功能中,您應該設置位置輸入文本框的值,而不是發出警報
function onSuccess(position) {
var input = document.getElementById('location');
input.value = position.coords.latitude + ', ' + position.coords.longitude;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.