选择警报框选项时页面跳转

我希望根据用户在警报框中的选择,将用户页面跳转到我网站的已定位部分。当警报框弹出时,如果他们确认自己拥有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语句会将用户从页面跳到正确的部分。


函数式编程
浏览 159回答 1
1回答

蓝山帝景

使用window.location.href =“ #SamsungStart”; 链接到您要访问的ID。<!--the Javascript function -->function Question() {var x=window.confirm("You have an iPhone right???")if (x)window.alert("Good!")elsewindow.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&nbsp;Security</a></h2></div>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript