switch语句中使用prompt时
为什么获取不到输入框中的数?
为什么获取不到输入框中的数?
2016-02-22
是这个:
<html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>switch</title>
<script type="text/JavaScript">
function DoSome(){
var myweek=prompt("今天是周几?","1");
switch(myweek)
{
case 1:
case 2:
document.write("学习理念知识");
break;
case 3:
case 4:
document.write("到企业实践");
break;
case 5:
document.write("总结经验");
break;
case 6:
case 7:
document.write("周六、日休息和娱乐");
default:
document.write("输入错误,不在1~7之间");
}
}
</script>
</head>
<body>
<input type="button" value="时间表" onClick="DoSome()">
</body>
</html>
是这样的吗?
<!DOCTYPE html>
<html>
<body>
<p>who are you?</p>
<button onclick="myFunction()">点击这里</button>
<p id="demo"></p>
<script>
function myFunction()
{
var x;
var name=prompt("Please enter your name")
switch (name)
{
case "Anny":
x="you are Anny!";
break;
case "Bnny":
x="you are Bnny!";
break;
case "Cnny":
x="you are Cnny!";
break;
default:
x="i don't know who are you!";
}
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html>
举报