简体   繁体   English

如何让 web 页面重定向?

[英]How to get the web page to redirect?

The thing is that is not working is that the page does not redirect to another page, weather if it is wrong or right.问题是页面没有重定向到另一个页面,如果它是错误或正确的天气。 I want the page to redirect to another page if the user guesses the generated word right.如果用户猜对了生成的单词,我希望页面重定向到另一个页面。

function myFunction() {
    if (document.getElementById("Enter_the_word").value == "KEYBOARD") {
        location.href = 'index4.html';
    } else {
      location.href = "index.html";
    }

  }

Your code has no issues but please try this reversed condition.您的代码没有问题,但请尝试这种相反的情况。 If it helps you.如果对你有帮助。

MY EDITED CODE BELOW -----------------下面是我编辑的代码 -----------------

var answerArr = ['KEYBOARD','MATH','FOOTBALL'];
if(answerArr.includes('MATH')){
    location.href = 'index4.html';
}else{
    location.href = 'index4.html';
}

Like this像这样

you just need to preventDefault the form submission, use this code to prevent it您只需要阻止默认表单提交,使用此代码来阻止它

document.querySelector('form').addEventListener('submit', (e) => {
      e.preventDefault();
  })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM