<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>switch</title><script type="text/JavaScript">function week(){ var num=document.getElementById("input1"); var x; var day=num.value; //alert(day); 可以显示day变量的值switch(day){ case 1: x="一"; document.write("今天是"+x+"!!"); break; case 2: x="二"; document.write("今天是"+x+"!!"); break; case 3: x="三"; document.write("今天是"+x+"!!"); break; case 4: x="四"; document.write("今天是"+x+"!!"); break; case 5: x="五"; document.write("今天是"+x+"!!"); break; default: x="六";}}</script></head><body> <input type="text" value="今天是星期几呢?" id="input1"> <input type="button" onclick="week()" value="go go go"></body></html>
2 回答
网友张顺飞
TA贡献1条经验 获得超0个赞
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>switch</title>
<script type="text/JavaScript">
function week(){
var num=document.getElementById("input1");
var x;
var day=num.value;
//alert(day);
switch(day)
{
case 1:
num.value=day;
x="一";
break;
case 2:
x="二";
break;
case 3:
x="三";
break;
case 4:
x="四";
break;
case 5:
x="五";
break;
}
alert(x);
}
</script>
</head>
<body>
<input type="text" value="今天是星期几呢?" id="input1">
<input type="button" onclick="week()" value="go go go">
</body>
</html>
添加回答
举报
0/150
提交
取消