作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
对这里发生的事情有点困惑:
var first = true;
var third = false;
if(first === true || !second || third === false) {
alert('if');
}
else{
alert('else');
}
else 语句每次都在这里求值,我很困惑为什么,第一个是 true,没有名为第二个的变量,第三个也是 false,只有一个必须为 true 才能触发 if 条件,对吧?
最佳答案
我认为您从 localStorage
获取一个字符串,并且没有将其转换为 bool 值。将字符串转换为 bool 值,它应该可以工作。
var first = 'true'; //string returned from localStorage
var third = 'false';
if (Boolean(first) === true || !second || Boolean(third) === false) {
alert('if');
}
else {
alert('else');
}
关于javascript - IF 语句中包含多个 OR 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26868164/
我是一名优秀的程序员,十分优秀!