<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<tr>
<td>请输入年: </td>
<td><input type="text" id="year" value=""/></td>
</tr>
<br>
<tr>
<td>请输入月: </td>
<td><input type="text" id="month" value=""/></td>
</tr>
<br>
<tr>
<td>请输入日: </td>
<td><input type="text" id="date" value=""/></td>
</tr>
<br>
<tr>
<td>请输出星期几:</td>
<td><input type="text" id="day"/></td>
</tr>
<br>
<tr>
<td><input type="button" value="计算" id="btn"/></td>
<td><input type="button" value="清空" id="res"/></td>
</tr>
</body>
</html>
<script>
var oYear = document.getElementById( "year" );
var oMonth = document.getElementById( "month" );
var oDate = document.getElementById( "date" );
var oBtn = document.getElementById( "btn" );
var oDay = document.getElementById( "day" );
var oRes = document.getElementById( "res" );
oBtn.onclick = function(){
var m = parseInt( oMonth.value );
var y = parseInt( oYear.value );
var d = parseInt( oDate.value );
var sum = 0;
switch( m ){
case 12 : sum += 30;//11月
case 11 : sum += 31;
case 10 : sum += 30;
case 9 : sum += 31;
case 8 : sum += 31;
case 7 : sum += 30;
case 6 : sum += 31;
case 5 : sum += 30;
case 4 : sum += 31; //3月
case 3 : {
y%4==0&&y%100!=0||y%400==0 ? sum += 29 : sum += 28;
}
case 2 : sum += 31; // 1月
case 1 : sum += d;
}
if( sum%7 == 0 ){
oDay.value = "星期天"
}else if( sum%7 == 1 ){
oDay.value = "星期一"
}else if( sum%7 == 2 ){
oDay.value = "星期二"
}else if( sum%7 == 3 ){
oDay.value = "星期三"
}else if( sum%7 == 4 ){
oDay.value = "星期四"
}else if( sum%7 == 5 ){
oDay.value = "星期五"
}else if( sum%7 == 6 ){
oDay.value = "星期六"
}
}
oRes.onclick = function(){
oYear.value="";
oMonth.value="";
oDate.value="";
oDay.value="";
}
</script>
<!-- alert( sum );-->
️我还很喜欢你、就像sin²x+cos²x始终如一