提示框重新创建自身,直到输入正确的字段
Prompt box to re-create itself until correct field has been entered
我有一些Javascript警报代码。我希望我的客户端能够输入一个代码来访问我的网站的一个区域。
此刻,我有一些JS代码,如果用户输入错误的凭据一个警告框被创建,用户选择ok,它去网站无论如何。这并不理想。
我怎样才能有一个循环,重新创建提示框,直到提供正确的凭据(变量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;
}
}
创建循环以迭代代码
试试这个,它可能对你有帮助
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");?>
}
}
}
试试:
if (person == x) {
alert("Success!");
window.location = 'index.php';
} // ...
如果您需要持续提示,您需要这样做。
试试: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);
}
}
}
相关文章:
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 而循环只设置php中输入字段中的第一个值
- 在输入字段中将最小金额设置为
- 如何在输入字段中的按钮的帮助下打开日历,该字段的类型为“=”;日期”;
- 如何在HTML输入字段中添加不可删除的后缀
- 互斥单选按钮和相应的输入字段
- 在IE9中的输入字段中输入焦点最近按钮
- 选中单选框时将属性添加到输入字段
- 当设置addFromAutocompleteOnly时,剩余文本将保留在输入字段中
- 我如何在数字插入中使用逗号,这样它就不会'不要破坏我的输入字段
- 在输入字段上有两个函数调用,一个在Blur上,一个不在Angular中
- 输入字段将't获取更新的值
- 如何选择多个输入字段并删除所需的属性
- 输入字段,只接受0到12之间的数字
- 单击鼠标,用MySQL数据填充html表单输入字段
- 使用jquery将输入字段转换为文本
- Model中的Typeahead返回空值以形成输入字段
- 如何从查询字符串中的输入字段发回文本
- 如何验证日期、月份和日期的3个独立输入字段;年使用jquery或javascript
- 将值传递给jquery创建的输入字段