今天群里某人的一个需求~ 见下图: 这个需求不难,但是用的地方还是挺多的,以下是实现: <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <mce:script type="text/javascript"><!-- function change() { var nowDate = new Date(); var start_date; var end_date; if(document.getElementById("r1").status==true){ str = nowDate.getFullYear() + "-" + (nowDate.getMonth()+1)+ "-" + nowDate.getDate(); start_date=str; end_date = str; } if(document.getElementById("r2").status==true){ var weekFirstDay=new Date(nowDate-(nowDate.getDay()-1)*86400000); var weekLastDay=new Date((weekFirstDay/1000+6*86400)*1000); start_date = weekFirstDay.getFullYear() + "-" + (weekFirstDay.getMonth()+1)+ "-" + weekFirstDay.getDate(); end_date = weekLastDay.getFullYear() + "-" + (weekLastDay.getMonth()+1)+ "-" + weekLastDay.getDate(); } if(document.getElementById("r3").status==true){ var monthFirstDay=new Date(nowDate.getYear(),nowDate.getMonth(),1); var monthNextFirstDay=new Date(nowDate.getYear(),nowDate.getMonth()+1,1); var monthLastDay=new Date(monthNextFirstDay-86400000); start_date = monthFirstDay.getFullYear() + "-" + (monthFirstDay.getMonth()+1)+ "-" + monthFirstDay.getDate(); end_date = monthLastDay.getFullYear() + "-" + (monthLastDay.getMonth()+1)+ "-" + monthLastDay.getDate(); } document.getElementById("start_date").value = start_date; document.getElementById("end_date").value = end_date; } // --></mce:script> </head> <body> <form id="d1" name="d1" action="#"> <label for="t"> 输入时间段: </label> <input type="text" name="start_date" id="start_date"> - <input type="text" name="end_date" id="end_date"> <input type="radio" name="radiobutton" value="radiobutton1" id="r1" οnclick="change();"/> <label for="r1"> 本日 </label> <input type="radio" name="radiobutton" value="radiobutton2" id="r2" οnclick="change();"/> <label for="r2"> 本周 </label> <input type="radio" name="radiobutton" value="radiobutton3" id="r3" οnclick="change();"/> <label for="r3"> 本月 </label> <input type="button" value="查询" οnclick="query()" /> </form> </body> </html>