在javascript中动态更改if语句中的条件

时间:2013-02-03 13:39:37

标签: javascript jquery google-chrome firefox if-statement

此代码是动态更改条件的,但是,此语句是由chrome识别和解释但不是fx,如何解决问题?感谢

if a % 2 == 0 
  var condition = b == c  || b == d;
else 
  var condition = b == e  || b == f ;

if (condition)
  ......

2 个答案:

答案 0 :(得分:4)

var condition = (a % 2 == 0) ? (b == c  || b == d) : (b == e  || b == f);

答案 1 :(得分:0)

像这样写:

var condition;
if (a % 2 == 0)
    condition = b == c  || b == d;
else 
    condition = b == e  || b == f ;

if (condition)
   ......