2011-03-10 69 views
1

如果是,爲什麼這段代碼不會提醒任何事情?做javascript switch語句case允許使用表達式

<html> 
<head> 
<script type="text/javascript"> 
    switch ("hello world") { 
     case "hello" + " world": 
     alert("Greeting was found."); 
     break; 
    case "goodbye": 
     alert("Closing was found."); 
     break; 
    default: 
     alert("Unexpected message was found."); 
} 
</head> 
</html> 
+0

無論如何,這個開關有什麼意義?爲什麼要將常量與其他常量進行比較? – 2011-03-10 14:01:12

+0

它適用於Chrome。 – 2011-03-10 14:02:55

+1

按我的預期工作,ff3.6 – meouw 2011-03-10 14:03:15

回答

1

Works for me在...

  • 火狐3.6
  • 鉻10

一個開關,你一般把它比作常量。你使用它的方式沒有什麼意義。

0

是的,它接受expressionsFrom the specification

CaseClause
情況下表達語句列表選擇

而且隨着其他人說,它似乎爲他們工作。你的真實代碼中可能有另一個錯誤。