[英]alert(); not working with jquery and bootstrap
alert function is not working with rest of the code (working using bootstrap,jquery,js) ,it works if i remove everything else below it. 警报功能不适用于其余代码(使用bootstrap,jquery,js),如果我删除其下面的所有其他内容,它将起作用。
<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语句相同
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. 在
while
循环以及if
语句中都使用=
运算符,这使得里面的条件始终为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--;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.