<bdo id='9glNo'></bdo><ul id='9glNo'></ul>

    <small id='9glNo'></small><noframes id='9glNo'>

    <tfoot id='9glNo'></tfoot>

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

      <legend id='9glNo'><style id='9glNo'><dir id='9glNo'><q id='9glNo'></q></dir></style></legend>
    2. jquery 在切换案例中使用范围?

      jquery Using ranges in switch cases?(jquery 在切换案例中使用范围?)
      <i id='x5maq'><tr id='x5maq'><dt id='x5maq'><q id='x5maq'><span id='x5maq'><b id='x5maq'><form id='x5maq'><ins id='x5maq'></ins><ul id='x5maq'></ul><sub id='x5maq'></sub></form><legend id='x5maq'></legend><bdo id='x5maq'><pre id='x5maq'><center id='x5maq'></center></pre></bdo></b><th id='x5maq'></th></span></q></dt></tr></i><div id='x5maq'><tfoot id='x5maq'></tfoot><dl id='x5maq'><fieldset id='x5maq'></fieldset></dl></div>
    3. <tfoot id='x5maq'></tfoot>
        • <bdo id='x5maq'></bdo><ul id='x5maq'></ul>

          <legend id='x5maq'><style id='x5maq'><dir id='x5maq'><q id='x5maq'></q></dir></style></legend>
            <tbody id='x5maq'></tbody>

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

                本文介绍了jquery 在切换案例中使用范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                开关盒通常是这样的

                Monday: 
                Tuesday: 
                Wednesday: 
                etc. 
                

                我想使用范围.

                from 1-12: 
                from 13-19:
                from 20-21:
                from 22-30:
                

                有可能吗?顺便说一句,我正在使用 javascript/jquery.

                Is it possible? I'm using javascript/jquery by the way.

                推荐答案

                你可以尝试滥用开关跌倒行为

                you could try abusing the switch fall through behaviour

                var x = 5;
                switch (x) {
                    case  1: case 2: case 3: case 4: ...
                        break;
                    case 13: case 14: case 15: ...
                        break;
                    ...
                }
                

                非常冗长

                或者你可以试试这个

                function checkRange(x, n, m) {
                    if (x >= n && x <= m) { return x; }
                    else { return !x; }
                }
                
                var x = 5;
                switch (x) {
                    case checkRange(x, 1, 12):
                        //do something
                        break;
                    case checkRange(x, 13, 19):
                    ...
                }
                

                这会让你得到你想要的行为.我在 checkRange 的 else 中返回 !x 的原因是为了防止将 undefined 传递到 switch 语句时出现问题.如果您的函数返回 undefined (就像 jdk 的示例一样)并且您将 undefined 传递给开关,那么第一个案例将被执行.!x 保证在任何相等性测试下都不等于 x,这是 switch 语句选择执行哪种情况的方式.

                this gets you the behaviour you would like. The reason i return !x in the else of checkRange is to prevent the problem of when you pass undefined into the switch statement. if your function returns undefined (as jdk's example does) and you pass undefined into the switch, then the first case will be executed. !x is guaranteed to not equal x under any test of equality, which is how the switch statement chooses which case to execute.

                这篇关于jquery 在切换案例中使用范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                在开发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 在一年的第一天返回前一年)

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

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

                        • <bdo id='rPIen'></bdo><ul id='rPIen'></ul>

                            <tbody id='rPIen'></tbody>