首页 > Web开发 > 详细

js switch 用法

时间:2019-04-24 23:47:23      阅读:195      评论:0      收藏:0      [点我收藏+]

 

//获取星期
//例子1
var day=new Date().getDay();
switch (day)
{
    case 6:
      x="Today it‘s Saturday";
      break;
    case 0:
      x="Today it‘s Sunday";
      break;
    default:
      x="Looking forward to the Weekend";
}

输出

"Looking forward to the Weekend"

 

 

//例子2
var day=new Date().getDay();
switch (day)
{
    case 0:
      x="Today it‘s Sunday";
      break;
    case 1:
      x="Today it‘s Monday";
      break;
    case 2:
      x="Today it‘s Tuesday";
      break;
    case 3:
      x="Today it‘s Wednesday";
      break;
    case 4:
      x="Today it‘s Thursday";
      break;
    case 5:
      x="Today it‘s Friday";
      break;
    case 6:
      x="Today it‘s Saturday";
      break;
}

输出

"Today it‘s Wednesday"

 

//例子3
switch(t.update_state)
{
    case 1:
        $(#h-progress-status .value).text("HdwUpdateRestarting")
        break;
    case 2:
        $(#h-progress-status .value).text("HdwUpdateRestartSuccess")
        break;
    case 3:
        $(#h-progress-status .value).text("HdwUpdateRestartFailure")
        break;
    case 11:
        $(#h-progress-status .value).text("HdwUpdateFlashWiping")
        break;
    case 12:
        $(#h-progress-status .value).text("HdwUpdateFlashWipeSuccess")
        break;
    case 13:
        $(#h-progress-status .value).text("HdwUpdateFlashWipeFailure")
        break;
    case 21:
        $(#h-progress-status .value).text("HdwUpdateFlashReprogramming")
        break;
    case 22:
        $(#h-progress-status .value).text("HdwUpdateFlashReprogramSuccess")
        break;
    case 23:
        $(#h-progress-status .value).text("HdwUpdateFlashReprogramFailure")
        break;
    case 31:
        $(#h-progress-status .value).text("HdwUpdateAppStarting")
        break;
    case 32:
        $(#h-progress-status .value).text("HdwUpdateAppStartSuccess")
        break;
    case 33:
        $(#h-progress-status .value).text("HdwUpdateAppStartFailure")
        break;
    default:
      console.log("something else!")
}

 

js switch 用法

原文:https://www.cnblogs.com/sea-stream/p/10765742.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!