所以我想循环这个功能,所以每次密码错误时都会出现提示,并在右边链接谷歌。你如何循环提示?
var input = prompt("Enter password");
if (input != "Philip") {
alert("Wrong Password")
} else {
window.open("http://google.com")
}
答案 0 :(得分:1)
我建议不要这样做,如果这是专业网站,因为它被认为是不好的用户体验。但是,如果这不是一个问题,一种方法是这样做:
var input = prompt('Enter password:');
while(input!=='correct'){
alert('Wrong password');
input = prompt('Enter password:');
}
window.location = 'https://google.com';
答案 1 :(得分:0)
这很容易做到一段时间,请参阅下面的代码:
// The first time user have a chance to input their passwd
var input = prompt("Enter password");
// loop checking if they right let they go next
while (input != "Philip") {
alert("Wrong Password")
var input = prompt("Enter password");
}
// if everything ok , do the rest of thing ~
window.open("http://google.com");
答案 2 :(得分:0)
使用while。
function checkPass(field) {
var x = document.getElementById("passw").value;
var regex = /^[a-z0-9]+$/;
var pw = document.getElementById("pw")
if (x.length < 5)
{
pw.innerHTML = "Min of 5 characters needed for Passphrase";
}
else if (field.value.length > 10)
{
pw.innerHTML = "Max characters for Passphrase is 10 characters";
}
else if(!regex.test(x))
{
pw.innerHTML = "Enter a valid Passphrase";
}
else{
pw.innerHTML = '';
}
}