JavaScript:输入类型Number不能与switch一起使用

时间:2020-05-16 07:38:20

标签: input

这是一个测试程序,用于了解如何使用开关。我想输入一个数字,然后对该数字进行切换操作。 如果我将输入type =“ number”更改为Text。可以,但是为什么不编号?

<input type="number" id="myday"/>
<button onclick="myFunction3()">Try it</button> </p> 
<h3 id="demo1"></h3>
<script>
function myFunction3() {
var x = document.getElementById("myday").value;
var day;
switch (x) {
  case 0:
    day = "Sunday";
    break;
  case 1:
    day = "Monday";
    break;
  case 2:
    day = "Tuesday";
    break;
  case 3:
    day = "Wednesday";
    break;
  case 4:
    day = "Thursday";
    break;
  case 5:
    day = "Friday";
    break;
  case  6:
    day = "Saturday";
    break;
  default:
     day = "No Value found";
}
document.getElementById("demo1").innerHTML = "Today is " + day;
}
</script>

如果我更改为输入文本,它将起作用。

0 个答案:

没有答案