Javascript倍数或条件检查 [英] Javascript multiple or condition check

查看:43
本文介绍了Javascript倍数或条件检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了一些简单的检查

I have struck with some simple if else checking

var IsCompanyContacttitleUpdate = false;
var ContactStatus = -1;

if ((IsCompanyContacttitleUpdate == false) && (ContactStatus == 2 || 3 || 4)) 
{
    alert('inside if');
}
else if (IsCompanyContacttitleUpdate == false && ContactStatus == 2) {
    alert('inside else if');
}
else {
    alert('yup yup else');
}

在这种情况下,我希望执行else部分.但它没有被解雇.请帮我解决这个问题...在此先感谢请看小提琴 http://jsfiddle.net/vuHYn/1/

In this case i expected to execute the else part. but its not fired. Please help me to solve this one... Thanks in advance please see the fiddle http://jsfiddle.net/vuHYn/1/

推荐答案

ContactStatus == 2 ||3 ||4 是无效的(也许无效不是正确的词,更准确地说,它没有按照您的想法做)

This ContactStatus == 2 || 3 || 4 is invalid (maybe invalid is not the correct word, to be more accurate let's say that it's not doing what you think it does)

对于您的情况,您需要使用

For your scenario you'll need to use

ContactStatus == 2 || ContactStatus == 3 || ContactStatus == 4

您的代码可以翻译成

ContactStatus == 2 || true || true

这始终是真的.

这篇关于Javascript倍数或条件检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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