问题
i facing issue my If statement returning always true, for each value.
var radioValue = parseInt($("input[name=packageRadio]:checked").val())
alert(radioValue); // 1000, 500, -1
if ((radioValue) == -1);
{
alert("no");
}
for every value alert("no")
is always calling.
回答1:
Remove semicolon after if
if ((radioValue) == -1){
alert("no");
}
回答2:
Remove semicolon ;
after if
.And also remove braces ()
rounded around radioValue
.
Like following
if (radioValue == -1){
alert("no");
}
回答3:
When JavaScript parsing, semicolon means the end of the statement (or line). By that code you separate if statement and it's body.
来源:https://stackoverflow.com/questions/61556125/if-statement-always-return-true-even-for-simple-integer-values