好的..如果用户采取任何行动,我必须清除 setTimeout 并且我不希望它继续并重定向到 Google。但它不起作用..有人可以看看这个吗?
script type="text/javascript">
function redirect() {
window.location = "https://google.com";
}
var timer = window.setTimeout("redirect()", 8000);
var capital = window.prompt("MY Question?","");
if(capital != null && capital.length < 1) {
clearTimeout(timer);
document.getElementById("firstdiv").innerHTML="Sorry.<br /> The answer is.";
}
else {
if(window.confirm("Is that your final answer?")){
document.getElementById("firstdiv").innerHTML = "The answer to the question is: " + capital + ", so says you.";}
else{
var capital = window.prompt("What is the capital of Missouri?","");
document.getElementById("firstdiv").innerHTML = "The answer to the question is: " + capital + ", so says you.";}
</script>