2
我正在試圖創建打印今天的日期創建在JavaScript/HTML日曆
但是日曆,我的日曆仍然是空白
與當我嘗試打印日曆整個日曆
因爲我不是通過HTML打印表格,而是試圖通過javascript打印表格。
var $ = function (id) { return document.getElementById(id); };
var getMonthText = function(currentMonth) {
if (currentMonth === 0) { return "January"; }
else if (currentMonth === 1) { return "February"; }
else if (currentMonth === 2) { return "March"; }
else if (currentMonth === 3) { return "April"; }
else if (currentMonth === 4) { return "May"; }
else if (currentMonth === 5) { return "June"; }
else if (currentMonth === 6) { return "July"; }
else if (currentMonth === 7) { return "August"; }
else if (currentMonth === 8) { return "September"; }
else if (currentMonth === 9) { return "October"; }
else if (currentMonth === 10) { return "November"; }
else if (currentMonth === 11) { return "December"; }
};
var getLastDayofMonth = function(currentMonth) {
var dt = new Date();
dt.setMonth(currentMonth +1);
dt.setDate(0);
return dt.getDate();
};
window.onload = function() {
//var year =
};
body {
font-family: Arial, Helvetica, sans-serif;
background-color: white;
margin: 0 auto;
width: 360px;
border: 3px solid blue;
padding: 0 2em 1em;
}
h1 {
color: blue;
margin-bottom: .25em;
}
table {
border-collapse: collapse;
border: 1px solid black;
}
td {
width: 3em;
height: 3em;
vertical-align: top;
padding: 0.5 0 0 0.5;
border: 1px solid black;
}
<title>Calendar</title>
<link rel="stylesheet" href="calendar.css">
<script src="calendar.js"></script>
<body>
<main>
<h1><span id="month_year"> </span></h1>
<table id="calendar">
<tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>
</table>
</main>
</body>
發佈提問與問題 –
https://jsfiddle.net/wtb1s7bf/ – steven
不要打擾一個小提琴,代碼在這裏運行。 – RobG