要加载的函数的多个if语句

时间:2013-05-20 16:32:13

标签: javascript if-statement boolean-logic

我正在尝试制作一个if语句,需要两个参数来加载函数,否则应该没有任何反应。

这里它表示form = false或者question.length == 0.但我不需要这个或者这个。

Jquery:

if (form == false || questions.length == 0 ) { 
    alert("You need to create at least one question to create a "+moduleName); 
} else { 
    //do something 
}

怎么做?

4 个答案:

答案 0 :(得分:3)

逻辑 ||

逻辑&&

if (form == false && questions.length == 0 ) { 
    alert("You need to create at least one question to create a "+moduleName); 
} else { 
    //do something 
}

答案 1 :(得分:3)

if (form == false && questions.length == 0 ) { 
    alert("You need to create at least one question to create a "+moduleName); 
} else { 
    //do something 
}

Tutorial

答案 2 :(得分:2)

在Javascript中使用双&符号(&&)作为AND子句:

if (form == false && questions.length == 0 ) { 
   alert("You need to create at least one question to create a "+
} else { 
   //do something 
}

答案 3 :(得分:1)

将OR更改为AND -

if (form == false && questions.length == 0 ) { 
    alert("You need to create at least one question to create a "+moduleName); 
} else { 
    //do something 
}