<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 语句中哪个条件为真?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                  Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                  Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)
                  How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
                  Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                  Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))
                    <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>