切换真假

时间:2018-12-11 13:51:35

标签: javascript toggle

我想知道如何将true切换为false,反之亦然:

function step1(enabled, withDialog) {
  if (enabled != undefined && !enabled)
    return;

  var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
  var desc1 = new ActionDescriptor();
  var ref1 = new ActionReference();
  ref1.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Msk '));
  desc1.putReference(cTID('null'), ref1);
  desc1.putBoolean(cTID('MkVs'), true);
  executeAction(cTID('slct'), desc1, dialogMode);

};

if (a == false) {
  !a = true;
} else if (a == true) {
  !a = false;
}

1 个答案:

答案 0 :(得分:0)

我不知道您要在代码中切换哪个变量,但请注意:

if(a == false) { a = true; } else if (a == true) { a = false; }

您可以将其更改为:

a = !a;