首页 > 代码库 > JS生成当月日历
JS生成当月日历
JS生成当月日历,效果图
完整代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <script type="text/javascript"> var months = new Array(); months[0] = "January"; months[1] = "Feburary"; months[2] = "March"; months[3] = "April"; months[4] = "May"; months[5] = "June"; months[6] = "July"; months[7] = "August"; months[8] = "September"; months[9] = "October"; months[10] = "November"; months[11] = "December"; var cur_date = new Date(); var cur_month = cur_date.getMonth(); cur_date.setDate(1); document.write("<table border=1 cellpadding=3 cellspacing=0>"); document.write("<tr>"); document.write("<td colspan=7 align=‘center‘>" + months[cur_month] + "</td>"); document.write("<tr>"); document.write("<td align=‘center‘>S</td>"); document.write("<td align=‘center‘>M</td>"); document.write("<td align=‘center‘>T</td>"); document.write("<td align=‘center‘>W</td>"); document.write("<td align=‘center‘>T</td>"); document.write("<td align=‘center‘>F</td>"); document.write("<td align=‘center‘>S</td>"); document.write("</tr>"); if (cur_date.getDay() != 0) {//如果1号不是星期天 document.write("<tr>"); for (i = 0; i < cur_date.getDay(); i++) { document.write("<td> </td>");}//输出1号前面空白的星期 } while (cur_date.getMonth()== cur_month) { if (cur_date.getDay == 0) {//星期天时换行<tr> document.write("<tr>"); } document.write("<td align=‘center‘>" + cur_date.getDate() + "</td>"); if (cur_date.getDay() == 6) { document.write("</tr>");//星期六时换行结束</tr> } cur_date.setDate(cur_date.getDate() + 1); } for(var i=cur_date.getDay();i<=6;i++){//输出月最后一天后面空白的星期 document.write("<td> </td>"); } document.write("</table>"); </script> </body> </html>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。