这是一段计算输入任意年月,得出相应月数天数的代码。
当输出代码改成document.write()时页面不显示,直接进行下一次循环。
我换成alert()则有显示弹窗。
想知道为什么document.write()不显示。
```javascript
<script>
// 当输入完成并得出结果后,循环该代码,以便进行下一次输入
while (true) {
// 输入两个数据并装存
const year = +prompt('请输入年份:')
const month = +prompt('请输入月份:')
// 判断是否为闰年的二月
if (month === 2) {
// 闰年二月29天
if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
// document.write('29天')
alert('29天')
// break
// 平年二月28天
} else {
// document.write('28天')
alert('28天')
// break
}
// 输入其他月份则区分大小月
} else {
// 大月31天
// alert(1)
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
// document.write('31天')
alert('31天')
// alert(2)
break
// 小月30天
case 4:
case 6:
case 9:
case 11:
// document.write('30天') /为什么document不显示,而alert能显示?
alert('30天')
break
// 输入不正确的月份弹出警告
default:
alert('输入的月份不正确!')
break
}
}
}
</script>
```