[英]alert(); not working with jquery and bootstrap
警报功能不适用于其余代码(使用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>
如果我以这种方式编写警报,它将起作用
<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>
问题是这一行:
while((c!=0)&&($("#user").text())=a)
您没有使用比较运算符。
更改为
while((c!=0)&&($("#user").text()) == a)
与您的if语句相同
if($("#pwd").text()=b)
更改为
if($("#pwd").text() == b)
看看是否可行
在while
循环以及if
语句中都使用=
运算符,这使得里面的条件始终为true。 改用==
运算符。
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.