如果执行了if语句,如何在延迟之后重定向
How to redirect after a delay if an if statement if fulfilled
我在我的一个朋友的请求下创建了一个随机的网站,问问题是什么(答案(一个网络笑话)是"他得到战利品了吗?"目前我有它来检查给出的密码,并根据它是否正确或错误写入文件。但我希望它,如果战利品的条件得到满足,重定向(5秒延迟后)到Tumblr,网站的敬畏。
这是我到目前为止的代码:)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The ultimate question</title>
<style>
body{
background-color:rgb(238, 235, 229);
}
#scriptresult{
font-family:calibri;
font-size:26px;
width:30%;
margin-left:35%;
text-align:center;
margin-top:15%;
border-color:rgb(91, 122, 221);
border-style:solid;
border-width:5px;
padding:20px;
background-color:rgb(240, 219, 200);
}
</style>
</head>
<body>
<div id="scriptresult">
<script language="Javascript">
var passcode;
passcode = prompt("What is the ultimate question? (Make sure to include the ? at the end)");
passcode = (passcode.toUpperCase());
document.write("Your guess was" + " " + passcode);
if (passcode == "DO HE GOT A BOOTY?" || passcode == "DO HE GOT THE BOOTY?" || passcode == "DO HE GOT DA BOOTY?") {
document.write("<br>Congratulations! You got da answer! Visit the awesomness!");
else if (passcode == "DOCTOR WHO?" || passcode == "WHAT IS THE MEANING OF LIFE?" || passcode == "WHAT IS THE DOCTORS NAME?" || passcode == "WHAT IS THE DOCTOR'S NAME?") {
document.write("<br>Not quite... But I love the guess! Think along the line of booty...<br><h6>(Hit refresh to try again)</h6>");
} else {
document.write("<br>Nope. That's wrong.<br><h6>(Hit refresh to try again)</h6>");
}
</script>
</div>
</body>
</html>
提前谢谢你!
将此代码插入到成功条件中。
setTimeout(function(){window.location.href="tumblr.com"},5000);
这将允许您在5秒后执行一个函数。
setTimeout(function() {
// Do redirect here...
}, 5000);
在你传递的if语句中:
window.setTimeout(function() {
location.href = "www.tumblr.com"; //is this the right link?
}, 5000);
相关文章:
- 如何在一个元素动画之后延迟
- 如何将角度动画延迟到模型绑定之后
- 在添加类之后,为DIPLAY内容添加延迟
- "脏的“;函数,需要脚本将触发延迟到加载数据之后
- 延迟似乎不会在元素上的 Stop(true, true) 之后延迟
- Boostrap远程模式:将动画延迟到加载之后
- 在showMessage()之后添加延迟
- 在执行服务之后延迟控制器初始化
- 延迟javascript函数,直到文件上传到asp页面之后
- 如何将脚本块的执行延迟到加载外部脚本之后
- jQuery -每次循环中addClass之后的延迟
- 如果执行了if语句,如何在延迟之后重定向
- 如何编制文档.在延迟文件之后再写.再写
- Javascript在HTML之后延迟呈现
- 在页面的其余部分之后加载脚本,而不延迟它
- 是否可以使一个变量的值依赖于对另一个变量的更改(有时在延迟之后)?
- 如何在数组中每个元素之后保持延迟
- 为什么这个动画只有在第一步之后才有延迟?
- 如何将backbone.js中的事件绑定延迟到某个时间之后
- Jquery函数在Keyup之后的某个时间延迟