利用了switch的穿透原理
<input type="number" id="year">年
<input type="number" id="month">月
<input type="number" id="day">日
<button id="btn1">查询</button>
<input type="number" id="tol">当前天
<script>
btn1.onclick = function () {
var y = year.value - 0;
var m = month.value - 0;
var d = day.value - 0;
var dd = 0;
var mm = m - 1;
switch (mm) {
case 12:
dd = dd + 31;
case 11:
dd = dd + 30;
case 10:
dd = dd + 31;
case 9:
dd = dd + 30;
case 8:
dd = dd + 31;
case 7:
dd = dd + 31;
case 6:
dd = dd + 30;
case 5:
dd = dd + 31;
case 4:
dd = dd + 30;
case 3:
dd = dd + 31;
case 2:
if (y % 4 === 0 && y % 100 !== 0 || y % 400 === 0){
dd = dd + 29;
}
else {
dd = dd + 28;
}
case 1: dd = dd + 31;
default:
dd = dd + d;
}
tol.value = dd;
}
</script>
转载请注明原文地址:https://ipadbbs.8miu.com/read-3702.html