```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>
```
prompt和alert是会阻塞进程的,当遇到他们的时候程序就会暂停
所以当document.write执行的时候,还没渲染就被下一次循环的prompt给阻塞进程了,document.write的渲染自然也暂停了