我已经获得了一些Javascript警报的代码。我希望我的客户能够输入代码来访问我网站的某个区域。
目前我有一些JS代码,如果用户输入了错误的凭据,则会创建一个警告框,用户选择好,然后无论如何都会进入网站。这不太理想。
如何提供重新创建提示框的循环,直到提供正确的凭据(变量x
)。
window.onload = function launch() {
var x = "name of credential";
var person = prompt("The website is under development\nPlease enter your development code:");
if (person == x) {
alert("Success!");
<?php header("Location : index.php");?>
}
else {
alert("You have entered the wrong credentials please try again!");
var person = prompt("The Care Socierty website is under development\nPlease enter your development code:");
}
克里希纳的建议
window.onload = function launch() {
var x = "credential";
var person = prompt("The website is under development\nPlease enter your development code:");
if (person == x) {
alert("Success!");
window.location;
}
else {
alert("You have entered the wrong credentials please try again!");
return false;
}
}
答案 0 :(得分:1)
试试:
if (person == x) {
alert("Success!");
window.location = 'index.php';
} // ...
答案 1 :(得分:1)
进行循环以迭代代码
试试这个可能会对你有所帮助
window.onload = function () {
var x = "name of credential";
var wrong = true;
while (wrong) {
var person = prompt("The website is under development\nPlease enter your development code:");
if (person == x) {
alert("Success!");
wrong = false;
<?php header("Location : index.php");?>
}
}
}
答案 2 :(得分:0)
如果你需要继续提示你需要做这样的事情。
在此尝试:http://jsbin.com/duroguji/2/edit
$(function () {
setTimeout(askPermission,1000);
});
function askPermission()
{
var success = false;
var x = "HELLO";
while(!success)
{
var person = prompt("The website is under development\nPlease enter your development code:", "");
if (person == x) {
success = true;
alert("Success!");
}
else {
alert("You have entered the wrong credentials please try again!");
setTimeout(askPermission,1000);
}
}
}