• javascript || && 简写 if


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    <script type="text/javascript">
     
        如果你想写
        if (!false)
        {
            alert('false');
        }
     
        不妨考虑写成:
        false || alert('false');
     
        false || alert('false'); true || alert('true'); //output false;
        "||"的情况下,第一个条件true,不检测第二个直接返回true.第一个条件false,会执行第二个条件检测
     
        false && alert('false'); true && alert('true'); //output true
        "&&"的情况下,第一个条件true,还会检测第二个条件。第一个条件false,直接返回false退出。
     
        简而言之, 替换 if 的简单实用, ? : 替换 if else的实用。 写短小精悍的代码
     
        usage:
        $("#regform input[type!=hidden]").each(
            function(index) {
                $(this).parent().has("div.valid-under").length || $('<div class="valid-under"></div>').appendTo($(this).parent());
            }
        );
     
    </script>
  • 相关阅读:
    Jmeter四种参数化方式
    微信公众号开发--服务器接入
    IIS调试程序
    vs连接GitHub
    vs2013 卸载
    Edge,IE浏览器 兼容模式设置
    XML非法字符的处理
    SQL Server Union联合查询
    SQL Server NULL的正确用法
    SQL Server Like 与 通配符
  • 原文地址:https://www.cnblogs.com/wlh-mm/p/4763882.html
Copyright © 2020-2023  润新知