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

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

      <tfoot id='pUibA'></tfoot>
        <bdo id='pUibA'></bdo><ul id='pUibA'></ul>
    1. <legend id='pUibA'><style id='pUibA'><dir id='pUibA'><q id='pUibA'></q></dir></style></legend>
      1. 如何检测窗口大小然后用 jquery switch 语句做一些事情

        时间:2023-09-08

        <tfoot id='grz5F'></tfoot>

            <tbody id='grz5F'></tbody>

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

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

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

                  <bdo id='grz5F'></bdo><ul id='grz5F'></ul>
                  本文介绍了如何检测窗口大小然后用 jquery switch 语句做一些事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想使用 jquery 检查窗口大小,并根据不同的分辨率更改背景图像.所以我想以某种方式在更多情况下使用switch"语句,但我只是不知道这会是什么样子.这是我想要的基本结构,但有更多选择:

                  i would like to check for the window size with jquery and based on the different resolutions i would like to change the background image. So i was thinking to somehow use the "switch" statement for more cases, but i just don't know how this would look like. This is the basic structure i want but with more options:

                  if ((screen.width>=1024) && (screen.height>=768)) {
                   //do something
                  }
                  else {
                  //do something else
                  }
                  

                  感谢您的帮助.

                  推荐答案

                  switch 语句不会让你做诸如检查特定值之间的数字之类的事情,它也不会让你检查在多个变量上,要么...

                  The switch statement won't let you do stuff like checking for numbers between certain values, and it won't let you check on multiple variables, either...

                  所以对于这个特定的场景,我认为最合适的实际上只是一个 if-elseif 语句的列表,就像你已经在做的那样.

                  So for this particular scenario, I think the best fit is actually just a list of if-elseif statements, like you're already on your way to do.

                  switch 中进行范围检查"真的很冗长:

                  To do "range checks" in switch is really verbose:

                  switch(windowWidth) {
                      case 1:
                      case 2:
                      case 3:
                      case 4:
                      case 5:
                          //Do something if value is less than or equal to 5
                          break;
                      case 6:
                      case 7:
                      case 8:
                      case 9:
                      case 10:
                          //Do something if value is higher than 5 AND less than or equal to 10
                          break;
                      ...
                      ...
                  }
                  

                  这篇关于如何检测窗口大小然后用 jquery switch 语句做一些事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从 switch 语句中返回是否被认为是比使用 break 更好的做法? 下一篇:YouTube iframe API:如何控制 HTML 中已有的 iframe 播放器?

                  相关文章

                  1. <legend id='ITlyK'><style id='ITlyK'><dir id='ITlyK'><q id='ITlyK'></q></dir></style></legend>
                    <tfoot id='ITlyK'></tfoot>
                      <bdo id='ITlyK'></bdo><ul id='ITlyK'></ul>

                    1. <small id='ITlyK'></small><noframes id='ITlyK'>

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