首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >If条件(多个条件)

If条件(多个条件)
EN

Stack Overflow用户
提问于 2020-07-21 13:41:27
回答 2查看 47关注 0票数 0

我的if条件需要帮助。

代码语言:javascript
复制
if(userId && !targetId){
// query logic for userid and no targetid
} 
else if (!userId && targetId){
// query logic for targeted and no user id
}

现在我该如何写"else“部分呢?当用户id和目标id都存在时的另一个查询逻辑。

EN

回答 2

Stack Overflow用户

发布于 2020-07-21 13:44:37

你可以简单地添加另一个if:

代码语言:javascript
复制
if (userId && !targetId) {
   // query logic for userid and no targetid
} 
else if (!userId && targetId) {
    // query logic for targeted and no user id
}
else if (userId && targetId) {
    // query logic for both true
}
else {
    // this defaults to both being false, the other three
    // conditions already being handled above
}
票数 3
EN

Stack Overflow用户

发布于 2020-07-21 13:45:28

你可以这样做

代码语言:javascript
复制
else
{
 if(userId && targetId){ }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63008080

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档