编辑:错误解决了!我在if()之后放了一个分号.谢谢保罗!
我刚刚到达这个奇怪的情况(该片段可以在http://jsfiddle.net/nUs7h/运行):
function check_if_tag_used()
{
var found = false;
return found;
}
var used = check_if_tag_used();
console.debug(used);
if (used);
{
alert("This should not appear!"); // why this runs?
}
Run Code Online (Sandbox Code Playgroud)
尽管如果假的是使用变量的值,为什么会显示alert()?请注意,console.debug()确实将其报告为false.
你的结尾有一个分号if.
if (used);
Run Code Online (Sandbox Code Playgroud)
去掉它.
仅供参考,这就是为什么我总是使用相同的支撑方式
if (used) {
alert("This should not appear!");
}
Run Code Online (Sandbox Code Playgroud)
要发生这种情况要困难得多.