2006-5-13 11:31:49
设置两个文档框的查询时间段
下面是javascript代码;
// JavaScript Document
//设置时间
function Setupdatetime(s,sv,e,ev)
{
var temp_sdate = new Date();
temp_sdate.setDate(temp_sdate.getDate()+sv);
document.getElementById(s).value=temp_sdate.getYear() + "-" + (temp_sdate.getMonth()+1) + "-" + temp_sdate.getDate();
var temp_edate=new Date();
temp_edate.setDate(temp_edate.getDate()+ev);
document.getElementById(e).value=temp_edate.getYear() + "-" + (temp_edate.getMonth()+1) + "-" + temp_edate.getDate();
}
//按周设置
function SetupWeek(s,sv,e)
{
var temp_sdate = new Date();
temp_sdate.setDate(temp_sdate.getDate()-(sv*7));
document.getElementById(e).value=temp_sdate.getYear() + "-" + (temp_sdate.getMonth()+1) + "-" + temp_sdate.getDate();
var day = temp_sdate.getDay();
temp_sdate.setDate(temp_sdate.getDate()-day);
document.getElementById(s).value=temp_sdate.getYear() + "-" + (temp_sdate.getMonth()+1) + "-" + temp_sdate.getDate();
}
//按月设置
function SetupMonth(s,sv,e)
{
var temp_sdate = new Date();
temp_sdate.setMonth(temp_sdate.getMonth()-sv)
document.getElementById(s).value=temp_sdate.getYear() + "-" + (temp_sdate.getMonth()+1) + "-" + "1";
if(sv==0){
document.getElementById(e).value=temp_sdate.getYear() + "-" + (temp_sdate.getMonth()+1) + "-" + temp_sdate.getDate();
}else
{
document.getElementById(e).value=temp_sdate.getYear() + "-" + (temp_sdate.getMonth()+1) + "-" + DateSelectorDaysInMonth(temp_sdate.getYear(),(temp_sdate.getMonth()+1));
}
}
//根据年和月获取当月的天数
function DateSelectorDaysInMonth(year, month)
{
var date = new Date(year,month,0);
return date.getDate();
}