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

        <bdo id='TAobo'></bdo><ul id='TAobo'></ul>
      <legend id='TAobo'><style id='TAobo'><dir id='TAobo'><q id='TAobo'></q></dir></style></legend>

      <small id='TAobo'></small><noframes id='TAobo'>

      1. <tfoot id='TAobo'></tfoot>

        我可以使用带有两个变量的 case/switch 语句吗?

        Can I use a case/switch statement with two variables?(我可以使用带有两个变量的 case/switch 语句吗?)

        <small id='5FWhx'></small><noframes id='5FWhx'>

          <bdo id='5FWhx'></bdo><ul id='5FWhx'></ul>
          <legend id='5FWhx'><style id='5FWhx'><dir id='5FWhx'><q id='5FWhx'></q></dir></style></legend>

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

                  本文介绍了我可以使用带有两个变量的 case/switch 语句吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 JavaScript 的新手,我的理解是使用一个 SWITCH/CASE 语句比使用一大堆 IF 语句要快.

                  I am a newbie when it comes to JavaScript and it was my understanding that using one SWITCH/CASE statements is faster than a whole bunch of IF statements.

                  但是,我想使用带有两个变量的 SWITCH/CASE 语句.

                  However, I want to use a SWITCH/CASE statement with two variables.

                  我的网络应用有两个滑块,每个滑块有五个状态.我希望行为基于这两个变量的状态.显然,这是一大堆 IF/THEN 语句.

                  My web app has two sliders, each of which have five states. I want the behavior to be based on the states of these two variables. Obviously that is a whole heck of a lot of IF/THEN statements.

                  我想到的一种方法是将两个变量连接成一个变量,然后我可以 SWITCH/CASE 那个.

                  One way I thought about doing it was concatenating the two variables into one and then I could SWITCH/CASE that.

                  有没有更好的方法来完成使用两个变量的 SWITCH/CASE ?

                  Is there a better way of accomplishing a SWITCH/CASE using two variables ?

                  谢谢!

                  推荐答案

                  是的,你也可以这样做:

                  Yes you can also do:

                      switch (true) {
                  
                       case (var1 === true && var2 === true) :
                         //do something
                         break;
                       case (var1 === false && var2 === false) :
                         //do something
                         break;
                  
                        default:
                  
                      }
                  

                  这将始终执行切换,与 if/else 非常相似,但看起来更简洁.只需继续检查 case 表达式中的变量即可.

                  This will always execute the switch, pretty much just like if/else but looks cleaner. Just continue checking your variables in the case expressions.

                  这篇关于我可以使用带有两个变量的 case/switch 语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                    <tbody id='QmAe9'></tbody>
                • <i id='QmAe9'><tr id='QmAe9'><dt id='QmAe9'><q id='QmAe9'><span id='QmAe9'><b id='QmAe9'><form id='QmAe9'><ins id='QmAe9'></ins><ul id='QmAe9'></ul><sub id='QmAe9'></sub></form><legend id='QmAe9'></legend><bdo id='QmAe9'><pre id='QmAe9'><center id='QmAe9'></center></pre></bdo></b><th id='QmAe9'></th></span></q></dt></tr></i><div id='QmAe9'><tfoot id='QmAe9'></tfoot><dl id='QmAe9'><fieldset id='QmAe9'></fieldset></dl></div>
                  <tfoot id='QmAe9'></tfoot>
                • <small id='QmAe9'></small><noframes id='QmAe9'>

                    <bdo id='QmAe9'></bdo><ul id='QmAe9'></ul>

                        1. <legend id='QmAe9'><style id='QmAe9'><dir id='QmAe9'><q id='QmAe9'></q></dir></style></legend>