我需要为学校项目制作日历小部件。我一直在努力在一周的正确日期获得正确的约会。我一直在尝试很多东西,但没有一个能奏效。还有几乎没有像样的指南或教程来处理日历。
有人可以给我一些帮助吗?
var dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var today = new Date();
var dag = today.getDay();
var myMonth = today.getMonth();
var jaar = today.getFullYear();
var volBtn = document.getElementById('Volgende');
var vorBtn = document.getElementById('Vorige');
function Kalender() {
var myHTML = '';
myHTML += '<div id="month">' + monthNames[myMonth] + " " + jaar + '</div><table id="cal">';
for (var i = 0; i < dayNames.length; i++) {
myHTML += '<th>' + dayNames[i] + ' ' + '</th>';
};
myHTML += '</tr>';
for (var i = 1; i <= monthLength[myMonth]; i++) {
myHTML += "<td><a href='#'>" + i + "</a></<td> ";
if (i % 7 == 0) {
myHTML += "</tr>";
}
}
myHTML += '</table>';
document.getElementById('div').innerHTML = myHTML;
}
if (myMonth == 1) {
if (jaar % 4 == 0) {
monthLength = 29;
};
};
var VolgendeFunc = function() {
myMonth = myMonth + 1;
if (myMonth == 11) {
volBtn.disabled = true;
vorBtn.disabled = false;
} else {
vorBtn.disabled = false;
volBtn.disabled = false;
}
document.getElementById('month').innerHTML = myMonth;
Kalender();
}
var VorigeFunc = function() {
myMonth = myMonth - 1;
if (myMonth == 0) {
vorBtn.disabled = true;
volBtn.disabled = false;
} else {
vorBtn.disabled = false;
volBtn.disabled = false;
}
document.getElementById('month').innerHTML = myMonth;
Kalender();
}
Kalender();
<html>
<head>
</head>
<body id="body">
<center>
<button id="Vorige" onclick="VorigeFunc()">Vorige</button> <button id="Volgende" onclick="VolgendeFunc()">Volgende</button>
<br>
<div id="div">
<script type="text/javascript" src="Kal.js"></script>
</div>
</center>
</body>
</html>