[英]how to implement 3 attempts login form using javascript prompt() method. it ddnt check for the next after 2nd attempt
I want to implement 3 attempts login form using javascript prompt() method.我想使用 javascript prompt() 方法实现 3 次尝试登录表单。 it shows You have left 2 attempt and ddnt check for the next attempt.
它显示您已经尝试了 2 次,并且 ddnt 检查下一次尝试。 how to solve this?
如何解决这个问题? here is my script
这是我的脚本
<script type="text/javascript">
var attempt = 3;
var userName=prompt("Username","");
var passWord=prompt("Password","");
if (userName+passWord=="john2541798432" || userName+passWord=="tim3591798752")
{
alert('success');
}
else
{
attempt --;// Decrementing by one.
alert("You have left "+attempt+" attempt;");
if( attempt == 0)
{
alert('you are blocked');
}
}
</script>
<script type="text/javascript">
var loggedin = false;
var attempt = 3;
while(!loggedin && attempt > 0){
var userName=prompt("Username","");
var passWord=prompt("Password","");
if (userName+passWord=="john2541798432" || userName+passWord=="tim3591798752")
{
loggedin = true;
alert('success');
}
else
{
attempt --;// Decrementing by one.
alert("You have left "+attempt+" attempt;");
if( attempt == 0)
{
alert('you are blocked');
}
}
}
</script>
According to your script, I think you can add a hidden input field and update the value of hidden field to verify the maximum attempt.根据您的脚本,我认为您可以添加一个隐藏输入字段并更新隐藏字段的值以验证最大尝试。 Please see the below script
请看下面的脚本
<input type="hidden" id="attempt" value="3">
<script type="text/javascript">
while(1)
{
var userName=prompt("Username","");
if(userName != "")
var passWord=prompt("Password","");
var attempt = document.getElementById("attempt").value;
if(userName != "" && passWord != "")
{
if (userName+passWord=="john2541798432" || userName+passWord=="tim3591798752")
{
alert('success');
break;
}
else
{
document.getElementById("attempt").value = attempt -1;
alert("You have left "+(attempt-1)+" attempt;");
attempt = attempt - 1;
if( attempt == 0)
{
alert('you are blocked');
break;
}
}
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.