【发布时间】:2015-11-23 17:56:23
【问题描述】:
您好,我正在寻找一些关于如何将此 switch 语句转换为 do 循环的建议。字符串函数和数字函数都执行其他程序,并且必须在按下 3 之前执行。任何帮助将不胜感激。
function Menu()
{
var menu =0;
document.write(" menu options " + name + "<br>");
document.write("option 1 stringFunction<br>");
document.write("option 2 numberFunction<br>");
document.write("option 3 goodbye<br>");
menu = prompt("please select a number between 1 and 3",0);
menu = parseInt(menu)
switch (menu)
{ // begin switch
case 1:
// begin case 1
document.write(name + " This is option 1<br> ") ;
stringFunction()
break ;
// end case 1
case 2:
// begin case 2
document.write(name + " This is option 2<br>") ;
numberFunction()
break ;
// end case 2
case 3:
// begin case 3
document.write('Goodbye ' + name) ;
break ;
// end case 3
default :
{// begin default
alert ("You must choose either 1,2,or 3");
}
} // end switch
} // end function
【问题讨论】:
-
这可能是您的解决方案:stackoverflow.com/questions/17072605/…
标签: javascript loops switch-statement