zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    C#.ToString()格式大全
    C# 中的正则验证及用法
    解除SVN的控制
    SVN检出忽略文件夹文件
    Mac下查看及生成SSH Key
    Xcode-报错问题总结大全
    CentOS6.5上kafka 安装过程-多机版本
    神经网络绘图网址
    CentOs 中没有eth0文件
    Spring 入门
  • 原文地址:https://www.cnblogs.com/wlh-mm/p/4763882.html
Copyright © 2011-2022 走看看