IF语句中的javascript多个OR条件 [英] javascript multiple OR conditions in IF statement

查看:74
本文介绍了IF语句中的javascript多个OR条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我在这里缺少一些基本知识.为什么第三个中频条件成立?条件不应该评估为假吗?我想做一些id不为1、2或3的事情.

I think I'm missing something basic here. Why is the third IF condition true? Shouldn't the condition evaluate to false? I want to do something where the id is not 1, 2 or 3.

var id = 1;
if(id == 1) //true    
if(id != 1) //false 
if(id != 1 || id != 2 || id != 3) //this returns true. why?

谢谢.

推荐答案

使用 OR (||)操作,如果任何一个条件为true,则结果为true.

With an OR (||) operation, if any one of the conditions are true, the result is true.

我认为您需要在此处进行 AND (&&)操作.

I think you want an AND (&&) operation here.

这篇关于IF语句中的javascript多个OR条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆