首页 > 代码库 > 上一周下一周
上一周下一周
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" > <title> 周选择工具 </title > </head > <body > <input name ="weekPicker" readonly ="readonly" type ="text" id ="weekPicker" style ="width:250px" > <input type ="button" name ="Submit" value ="http://www.mamicode.com/上一周" onClick ="javascript:pickWeek(-1)" > <input type ="button" name ="Submit2" value ="http://www.mamicode.com/下一周" onClick ="javascript:pickWeek(1)" > <script type ="text/javascript" > function getThisWeek(year,month,day) { var today = new Date(year,month - 1 ,day); var week = today.getDay(); if (week == 0 ) { week = 7 ; } var monday = new Date(today.valueOf() - (week - 1 ) * 24 * 60 * 60 * 1000 ); var sunday = new Date(monday.valueOf() + 6 * 24 * 60 * 60 * 1000 ); return monday.getFullYear() + "-" + ((monday.getMonth() + 1 ).toString().length == 1 ? ( "0" + (monday.getMonth() + 1 )):(monday.getMonth() + 1 )) + "-" + (monday.getDate().toString().length == 1 ? "0" + monday.getDate():monday.getDate()) + " 到 " + sunday.getFullYear() + " - " + ((sunday.getMonth() + 1 ).toString().length == 1 ? ( "0" + (sunday.getMonth() + 1 )):(sunday.getMonth() + 1 )) + "-" + (sunday.getDate().toString().length == 1 ? "0" + sunday.getDate():sunday.getDate()); } function getPreviousWeek(year,month,day) { var today = new Date(year,month - 1 ,day); var week = today.getDay(); if (week == 0 ) { week = 7 ; } var monday = new Date(today.valueOf() - (week + 6 ) * 24 * 60 * 60 * 1000 ); var sunday = new Date(monday.valueOf() + 6 * 24 * 60 * 60 * 1000 ); return monday.getFullYear() + "-" + ((monday.getMonth() + 1 ).toString().length == 1 ? ( "0" + (monday.getMonth() + 1 )):(monday.getMonth() + 1 )) + "-" + (monday.getDate().toString().length == 1 ? "0" + monday.getDate():monday.getDate()) + " 到 " + sunday.getFullYear() + " - " + ((sunday.getMonth() + 1 ).toString().length == 1 ? ( "0" + (sunday.getMonth() + 1 )):(sunday.getMonth() + 1 )) + "-" + (sunday.getDate().toString().length == 1 ? "0" + sunday.getDate():sunday.getDate()); } function getNextWeek(year,month,day) { var today = new Date(year,month - 1 ,day); var week = today.getDay(); if (week == 0 ) { week = 7 ; } var monday = new Date(today.valueOf() - (week - 8 ) * 24 * 60 * 60 * 1000 ); var sunday = new Date(monday.valueOf() + 6 * 24 * 60 * 60 * 1000 ); return monday.getFullYear() + "-" + ((monday.getMonth() + 1 ).toString().length == 1 ? ( "0" + (monday.getMonth() + 1 )):(monday.getMonth() + 1 )) + "-" + (monday.getDate().toString().length == 1 ? "0" + monday.getDate():monday.getDate()) + " 到 " + sunday.getFullYear() + " - " + ((sunday.getMonth() + 1 ).toString().length == 1 ? ( "0" + (sunday.getMonth() + 1 )):(sunday.getMonth() + 1 )) + "-" + (sunday.getDate().toString().length == 1 ? "0" + sunday.getDate():sunday.getDate()); } function pickWeek(id) { var year; var month; var day; if (id == 0 ) { var today = new Date(); year = today.getFullYear(); month = today.getMonth() + 1 ; day = today.getDate(); } else { var today = document.getElementById("weekPicker" ).value.split( "到" )[0].split("-"); year = today[0]; month = today[1]; day = today[2]; } switch (id) { case 0: { document.getElementById("weekPicker").value = http://www.mamicode.com/getThisWeek(year,month,day);"weekPicker").value = http://www.mamicode.com/getNextWeek(year,month,day);"weekPicker").value = http://www.mamicode.com/getPreviousWeek(year,month,day);>
上一周下一周
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。