用if表示

时间:2016-03-21 04:03:10

标签: javascript

如何为else if语句写简写?

if (showvar == "instock"){
   //show available
} else if (showvar == "final3"){
  //show only 3 available
} else {
  //show Not available
}

我知道只在ifelse时才会写。但是如果有else if语句,我该怎么写?

(showvar == "instock")? //show available : //show Not available

1 个答案:

答案 0 :(得分:6)

您只需将else if嵌套在false的{​​{1}}侧; :条款也只是else。像这样......

false