昨天改一個jsp頁面,想在js中加一個switch語句,一直沒成功。今天上午耐心嘗試着,終於成功了。
代碼如下:
function disSection(){
var len=document.getElementById("len").value;
switch(len){
case "4"
:
alert("i am here");
document.getElementById("option4").style.display="inline";
break;
case "5"
:
document.getElementById("option4").style.display="inline";
document.getElementById("option5").style.display="inline";
break;
case "6"
:
document.getElementById("option4").style.display="inline";
document.getElementById("option5").style.display="inline";
document.getElementById("option6").style.display="inline";
break;
default:
break;
};
}
window.onload=disSection;
注意 :
1 case 後的如果不是變量需加雙引號""
2 swich結束的花擴符外要加分號;