javascript Operators switch/case
| switch/case | NN 4 IE 4 ECMA 3 |
|
Provides a shortcut to execution paths for numerous conditions of an expression. The optional break statement at the end of each case block shortcuts execution of the switch statement, and also prevents the inadvertent execution of the default block, if present. |
|
| Example | |
var productList = document.forms[0].prodList;
var chosenItem = productList.options[productList.selectedIndex].value;
switch(chosenItem) {
case "Small Widget":
document.forms[0].price.value = "44.95";
break;
case "Medium Widget":
document.forms[0].price.value = "54.95";
break;
case "Large Widget":
document.forms[0].price.value = "64.95";
break;
default:
document.forms[0].price.value = "Nothing Selected";
}
|
|
Previous: javascript Operators this
1543,Nickname,Homepage or email,Comments here,Add comment
