alert function is not working with rest of the code (working using bootstrap,jquery,js) ,it works if i remove everything else below it.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js">
</script>
<script>
var c=3;
var a="user";
var b="123";
$("#b1").on('click', function () {
alert("Hi");
while((c!=0)&&($("#user").text())=a)
{
if($("#pwd").text()=b)
{
$("#modal").text("Log In Successful") ;
}
else{
$("#modal").text("Sign in failed, try again,"+c+" chances left") ;
c--;
}
}
});
</script>
If i write the alert in this fashion , it works
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js">
</script>
<script>
var c=3;
var a="user";
var b="123";
$("#b1").on('click', function () {
alert("Hi");
});
</script>
the problem is this line:
while((c!=0)&&($("#user").text())=a)
you are not using the comparison operator.
change it to
while((c!=0)&&($("#user").text()) == a)
same with your if statement
if($("#pwd").text()=b)
change it to
if($("#pwd").text() == b)
and see if that works
You are using =
operator in your while
loop as well as in your if
statement, which makes the condition inside always true. Use the ==
operator instead.
while((c!=0)&&($("#user").text())==a){
if($("#pwd").text()==b){
$("#modal").text("Log In Successful") ;
}
else{
$("#modal").text("Sign in failed, try again,"+c+" chances left") ;
c--;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.