【发布时间】:2018-04-23 16:33:54
【问题描述】:
我的目标是使用 OR 语句列表检查给定成分的不同属性,但它返回意外 ||错误。
$(".ingredient.clicked").each(function() {
if (typeof $(this).attr("noAddedSugar") != "undefined")
|| (typeof $(this).attr("vegan") != "undefined")
|| (typeof $(this).attr("glutenfree") != "undefined")
{
$('#proba').text("Proba");
} else {
$('#proba').text("");
return false;
}
});
当我单独添加和修改变量时它有效,当我使用 OR 时无效。任何意见将不胜感激。
谢谢!
【问题讨论】:
-
这不是有效的 JS。检查您的控制台是否有错误。
-
你打开了")"条件,typeof $(this).attr("noAddedSugar") != "undefined") 需要先打开
-
if-syntax is
if(expression)notif (expression) || (expression)所以你需要if ((expression) || (expression))
标签: javascript jquery conditional-statements