zoukankan      html  css  js  c++  java
  • JS If...Else

    JS If...Else


    条件语句用于基于不同的条件来执行不同的动作。


    条件语句

    通常在写代码时,您总是需要为不同的决定来执行不同的动作。您可以在代码中使用条件语句来完成该任务。
    在 JavaScript 中,我们可使用以下条件语句:

    • if 语句 - 只有当指定条件为 true 时,使用该语句来执行代码
    • if...else 语句 - 当条件为 true 时执行代码,当条件为 false 时执行其他代码
    • if...else if....else 语句 - 使用该语句来选择多个代码块之一来执行
    • switch 语句 - 使用该语句来选择多个代码块之一来执行

    If 语句

    if (条件)
      {
      只有当条件为 true 时执行的代码
      }
    

    注意:请使用小写的 if。使用大写字母(IF)会生成 JavaScript 错误!


    If...else 语句

    if (条件)
      {
      当条件为 true 时执行的代码
      }
    else
      {
      当条件不为 true 时执行的代码
      }
    

    If...else if...else 语句

    if (条件 1)
      {
      当条件 1 为 true 时执行的代码
      }
    else if (条件 2)
      {
      当条件 2 为 true 时执行的代码
      }
    else
      {
      当条件 1 和 条件 2 都不为 true 时执行的代码
      }
    

  • 相关阅读:
    Java并发编程:线程池的使用
    AlarmManager与PendingIntent
    ConnectivityManager与检查网络连接的使用
    IntentService的使用
    Service(Local Service)简介
    Looper、Hander、HandlerThread
    XML_PULL解析
    android AsyncTask 的使用(转载)
    android 连接网络的简单实例
    xml drawable
  • 原文地址:https://www.cnblogs.com/chao8888/p/11383328.html
Copyright © 2011-2022 走看看