主页 > 前端 > javascript >
来源:未知 时间:2017-03-20 12:06 作者:xxadmin 阅读:次
[导读] 效果图: 代码如下: !DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//ENhtmlheadmetahttp-equiv=Content-Typecontent=text/html;charset=utf-8/title日历操作/titlescriptwindow.onload=function(){varcells=document.getElementById(moni...
效果图: 代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>日历操作</title> <script> window.onload = function(){ var cells = document.getElementById('monitor').getElementsByTagName('td'); var clen = cells.length; var currentFirstDate; var formatDate = function(date){ var year = date.getFullYear()+'年'; var month = (date.getMonth()+1)+'月'; var day = date.getDate()+'日'; var week = '('+['星期天','星期一','星期二','星期三','星期四','星期五','星期六'][date.getDay()]+')'; return year+month+day+' '+week; }; var addDate= function(date,n){ date.setDate(date.getDate()+n); return date; }; var setDate = function(date){ var week = date.getDay()-1; date = addDate(date,week*-1); currentFirstDate = new Date(date); for(var i = 0;i<clen;i++){ cells[i].innerHTML = formatDate(i==0 ? date : addDate(date,1)); } }; document.getElementById('last-week').onclick = function(){ setDate(addDate(currentFirstDate,-7)); }; document.getElementById('next-week').onclick = function(){ setDate(addDate(currentFirstDate,7)); }; setDate(new Date()); } </script> </head> <body> <button id="last-week">上一周</button><button id="next-week">下一周</button> <table id="monitor"> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </table> </body> </html> |
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com