简体   繁体   English

验证带有密码和onclick的提示,转到特定链接javascript

[英]Verifying a prompt with a password and onclick go to a specific link javascript

var i = prompt("Enter The Password:");
    if (i === "hawaiian tropical" || "Hawaiian Tropical") {
        onclick="location.href='';"
    }

there is the code. 有代码。 as you see, i am trying to make sure the password is 1 of the 2 and if they are, go to a specific link. 如您所见,我正在尝试确保密码为2个密码中的1个,如果是,请转到特定链接。 But right now it is not working. 但是现在它不起作用。 Any suggestions? 有什么建议么?

I am a bit confused. 我有点困惑。 The title and the body of the question each ask for two different things. 问题的标题和正文分别要求两个不同的内容。 If you want to go to a specific URL if the password is correct, then this would work: 如果您想输入正确的密码(如果密码正确),则可以执行以下操作:

var i = prompt("Enter The Password:");
if (i === "hawaiian tropical" || i === "Hawaiian Tropical") {
  window.location.href = '';
}

While if you want to go to a specific URL when the password is correct and a button is clicked, use this: 如果您想在密码正确并单击按钮后转到特定的URL,请使用以下命令:

 var i = prompt("Enter The Password:"); if (i === "hawaiian tropical" || i === "Hawaiian Tropical") { document.getElementById("myBtn").onclick = window.location.replace(''); } 
 <button id="myBtn">Click here</button> 

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

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