我有这个 javascript switch 语句:
function showSideMenu() {
switch (document.forms["culinaryrequest"].culinarytype.selectedIndex) {
case 0:
document.getElementById('case1').style.display="none";
document.getElementById('case2').style.display="none";
document.getElementById('case3').style.display="none";
document.getElementById('case4').style.display="none";
break;
case 1:
document.getElementById('case1').style.display="table-row";
document.getElementById('case2').style.display="none";
document.getElementById('case3').style.display="none";
document.getElementById('case4').style.display="none";
break;
case 2:
document.getElementById('case1').style.display="none";
document.getElementById('case2').style.display="table-row";
document.getElementById('case3').style.display="none";
document.getElementById('case4').style.display="none";
break;
case 3:
document.getElementById('case1').style.display="none";
document.getElementById('case2').style.display="none";
document.getElementById('case3').style.display="table-row";
document.getElementById('case4').style.display="none";
break;
case 4:
document.getElementById('case1').style.display="none";
document.getElementById('case2').style.display="none";
document.getElementById('case3').style.display="none";
document.getElementById('case4').style.display="table";
break;
default:
break;
}
}
当用户从下拉菜单中选择一个选项时,它会显示由上述 switch 语句控制的某个元素。问题出在刷新时,或者如果用户遇到错误并被带回页面,则该元素再次被隐藏。我想设置一个 cookie 以保持元素显示,但我不确定如何将 cookie 添加到 switch 语句中。我可以举个例子吗?谢谢!