gpt4 book ai didi

javascript - 选择警告框选项时跳转页面

转载 作者:行者123 更新时间:2023-11-28 02:23:13 25 4
gpt4 key购买 nike

我希望根据用户在警告框中的选择将页面跳转到我网站的已锚定部分。当警告框弹出时,如果他们确认他们有 iPhone(这只是信息,设备真的无关紧要),它应该说“酷”并将他们留在原处,因为 iPhone 信息从顶部开始。但是,如果他们取消,我希望他们的页面跳转到 Android 信息开始的页面底部。

我一直在浏览堆栈溢出和其他各种网站,但我找不到解决这个问题的东西,但如果我错了,请原谅。

<!--the Javascript function -->

function Question() {
var x=window.confirm("You have an iPhone right???")
if (x)
window.alert("Good!")
else
window.alert("Here is info for your device type!")
}

<!-- the html im looking to jump to -->

<h2 id = galaxyInt><a id = "SamsungStart">Samsung Galaxy Mobile
Security</a></h2>

我希望通过不点击警告框来确认 else 语句会将用户从页面跳转到正确的部分。

最佳答案

使用 window.location.href = "#SamsungStart";链接到您要访问的 ID。

<!--the Javascript function -->

function Question() {
var x=window.confirm("You have an iPhone right???")
if (x)
window.alert("Good!")
else
window.location.href = "#SamsungStart";
}
Question();
#top{
width:100%;
height:300px;
float:left;
background-color:blue;
}
.container2{
width:100%;
height:400px;
float:left;
background-color:green;

}
#galaxyInt{
width:100%;
float:left;

}
#SamsungStart{
width:100%;
float:left;
}
<!-- the html im looking to jump to -->

<div id = "top"></div>



<div class="container2">
<h2 id = "galaxyInt"><a id = "SamsungStart">Samsung Galaxy Mobile
Security</a></h2></div>

关于javascript - 选择警告框选项时跳转页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56096788/

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