我遇到一个显示星期几的switch语句问题。我想从用户那里输入一个数字,并显示星期几。这是我的源代码,请指出我的函数出了什么问题。
let clickButton = document.getElementById("button");
clickButton.addEventListener("click", function weekDay() {
let day = Number(document.getElementById("numberDay").value);
switch (day) {
case 0:
alert("It's Sunday!")
break;
case 1:
alert("It's Monday");
break;
case 2:
alert("It's Tuesday");
break;
case 3:
alert("It's Wednesday");
break;
case 4:
alert("It's Thursday");
break;
case 5:
alert("It's Friday");
break;
case 6:
alert("It's Saturday");
break;
}
})
Enter a number: <input type="text" id="numberDay">
<button id="button">OK</button>
答案 0 :(得分:0)
您的代码看起来不错。但是,如果用户输入的数字不是0-6,则可能要添加默认大小写。 也许还要为周日使用7号添加另一种情况。
...
.addSuperinterface(ParameterizedTypeName.get(
ClassName.get(JsonSerializer.class),//rawType
TypeName.get(element.asType()) //the value for T
))
...
还可以将输入类型从preg_replace_callback
更改为class="nopopup"
switch (day) {
case 0:
case 7:
alert("It's Sunday!")
break;
case 1:
alert("It's Monday");
break;
case 2:
alert("It's Tuesday");
break;
case 3:
alert("It's Wednesday");
break;
case 4:
alert("It's Thursday");
break;
case 5:
alert("It's Friday");
break;
case 6:
alert("It's Saturday");
break;
default:
alert("Wrong input!");
break;
}
或者您还有其他问题吗?