作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有办法在 If 语句中设置多个内容?例如,在下面的代码中,如果某件事是真或假,我想设置状态和图标变量。这段代码不起作用,我怀疑这是因为 && 无法计算,但找不到解决方案。有什么建议吗?
var status;
var icon;
if(x.life > 0) {
status = "Yes" && icon == "fa-check-circle-o"
} else {
status = "No" && icon == " fa-times-circle-o"
}
最佳答案
Is there a way to set multiple things in an If statement? For example in the below code, I want to set both status and icon variables if something is true or false.
当然,这是可能的,但是,它当前不起作用,因为您没有正确分配值。使用单值 ( =
) 进行赋值,使用双值 ( ==
) 进行比较(将返回 boolean
)。
试试这个:
var status;
var icon;
if(x.life > 0) {
status = "Yes";
icon = "fa-check-circle-o";
} else {
status = "No";
icon = " fa-times-circle-o";
}
关于javascript - If 语句 js 中有多个内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43197415/
我是一名优秀的程序员,十分优秀!