<legend id='0smeW'><style id='0smeW'><dir id='0smeW'><q id='0smeW'></q></dir></style></legend>

<i id='0smeW'><tr id='0smeW'><dt id='0smeW'><q id='0smeW'><span id='0smeW'><b id='0smeW'><form id='0smeW'><ins id='0smeW'></ins><ul id='0smeW'></ul><sub id='0smeW'></sub></form><legend id='0smeW'></legend><bdo id='0smeW'><pre id='0smeW'><center id='0smeW'></center></pre></bdo></b><th id='0smeW'></th></span></q></dt></tr></i><div id='0smeW'><tfoot id='0smeW'></tfoot><dl id='0smeW'><fieldset id='0smeW'></fieldset></dl></div>
    <bdo id='0smeW'></bdo><ul id='0smeW'></ul>

      1. <tfoot id='0smeW'></tfoot>

        <small id='0smeW'></small><noframes id='0smeW'>

      2. 如何知道 if 语句中哪个条件为真?

        How to know which condition was true in an if statement?(如何知道 if 语句中哪个条件为真?)

            <small id='2S5wS'></small><noframes id='2S5wS'>

            <tfoot id='2S5wS'></tfoot>
              <tbody id='2S5wS'></tbody>
            <legend id='2S5wS'><style id='2S5wS'><dir id='2S5wS'><q id='2S5wS'></q></dir></style></legend>

            <i id='2S5wS'><tr id='2S5wS'><dt id='2S5wS'><q id='2S5wS'><span id='2S5wS'><b id='2S5wS'><form id='2S5wS'><ins id='2S5wS'></ins><ul id='2S5wS'></ul><sub id='2S5wS'></sub></form><legend id='2S5wS'></legend><bdo id='2S5wS'><pre id='2S5wS'><center id='2S5wS'></center></pre></bdo></b><th id='2S5wS'></th></span></q></dt></tr></i><div id='2S5wS'><tfoot id='2S5wS'></tfoot><dl id='2S5wS'><fieldset id='2S5wS'></fieldset></dl></div>
              <bdo id='2S5wS'></bdo><ul id='2S5wS'></ul>
                • 本文介绍了如何知道 if 语句中哪个条件为真?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我如何知道 JavaScript 中 if 语句中的哪个条件为真?

                  How can I know which condition in an if statement in JavaScript was true?

                  if(a === b || c === d){ console.log(correctValue) }
                  

                  我怎么知道它是 a === b 还是 c === d?

                  How can I know if it was either a === b or c === d?

                  我想知道除了检查每个条件自己的 if 语句之外是否还有其他方法.

                  I wanted to know if there was any way of doing this besides checking each condition on it's own if statement.

                  推荐答案

                  你不能.
                  如果它很重要,它需要是两个不同的条件.

                  You can't.
                  If it matters, it needs to be two different conditions.

                  if (a == b) {
                    // it was a == b
                    return true;
                  }
                  
                  if (c == d) {
                    // it was c == d
                    return true;
                  }
                  

                  请注意,即使如此,您也不会知道这两种情况还是只有一种为真.
                  如果你也想知道这一点,你需要一个额外的 if:

                  Note that even so, you won't know if both or just one of these conditions is true.
                  If you want to know this as well, you'll want an additional if:

                  if (a == b && c == d) {
                    // a == b and c == d
                  } else if (a == b) {
                    // just a == b
                  } else if (c == d) {
                    // just c == d
                  }
                  
                  return (a == b || c == d);
                  

                  这篇关于如何知道 if 语句中哪个条件为真?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                    <i id='8hdqe'><tr id='8hdqe'><dt id='8hdqe'><q id='8hdqe'><span id='8hdqe'><b id='8hdqe'><form id='8hdqe'><ins id='8hdqe'></ins><ul id='8hdqe'></ul><sub id='8hdqe'></sub></form><legend id='8hdqe'></legend><bdo id='8hdqe'><pre id='8hdqe'><center id='8hdqe'></center></pre></bdo></b><th id='8hdqe'></th></span></q></dt></tr></i><div id='8hdqe'><tfoot id='8hdqe'></tfoot><dl id='8hdqe'><fieldset id='8hdqe'></fieldset></dl></div>

                          <bdo id='8hdqe'></bdo><ul id='8hdqe'></ul>

                          <small id='8hdqe'></small><noframes id='8hdqe'>

                          <legend id='8hdqe'><style id='8hdqe'><dir id='8hdqe'><q id='8hdqe'></q></dir></style></legend>

                            <tbody id='8hdqe'></tbody>

                          1. <tfoot id='8hdqe'></tfoot>