gpt4 book ai didi

javascript - 将 Javascript 变量写入 - 无需 onclick

转载 作者:行者123 更新时间:2023-11-28 20:58:06 25 4
gpt4 key购买 nike

这是最新的

有人知道为什么这不会重定向吗?

 function onGeoSuccess(event)
{
document.getElementById("Latitude").value = event.coords.latitude;
document.getElementById("Longitude").value = event.coords.longitude;
document.getElementById("location").href = "track.cfm?track=s&Lat=" + event.coords.latitude + "&Long=" + event.coords.longitude;

var redirectUrl = "track.cfm?track=s&Lat=" + event.coords.latitude + "&Long=" + event.coords.longitude;

}

function redirect()
{
window.location.href = redirectUrl;
}
setTimeout(redirect,15000);

我陷入了大脑放屁模式,似乎无法将 javascript 变量写入 A anchor href。有想法吗?我确信我错过了一些简单的东西......

所以 Javascript 正在将 GPS 拉到下面 - 工作正常......

我需要它来将纬度和经度填充到 anchor href...没有“onclick” - 需要自动填充...

所以:

 <a href="page.htm?Lat=javascript(latitude)&Long=javascript(longitude)">GPS Location</a>

javascript(latitude) - is variable I need to pull from below Javascript
javascript(longitude) - is variable I need to pull from below Javascript

<script type="text/javascript">
function getLocationConstant()
{
if(navigator.geolocation)
{
navigator.geolocation.watchPosition(onGeoSuccess,onGeoError);
} else {
alert("Your browser or device doesn't support Geolocation");
}
}

// If we have a successful location update
function onGeoSuccess(event)
{
document.getElementById("Latitude").value = event.coords.latitude;
document.getElementById("Longitude").value = event.coords.longitude;

}

// If something has gone wrong with the geolocation request
function onGeoError(event)
{
alert("Error code " + event.code + ". " + event.message);
}

</script>

最佳答案

<a href="" id="location">GPS Location</a>

<script>
function onGeoSuccess(event)
{
document.getElementById("Latitude").value = event.coords.latitude;
document.getElementById("Longitude").value = event.coords.longitude;

document.getElementById("location").href = "page.htm?Lat=" + event.coords.latitude + "&Long=" + event.coords.longitude;
}
</script>

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