<script language="javascript" type="text/javascript">
function setStartDate(day) {
AddTime(day, "d");
}
function AddTime(AddDate, types) {
var EndDate = new Date(document.getElementById("<%=txt_DateEnd.ClientID%>").value.replace(/-/g, "/"));
var StartDate = new Date(document.getElementById("<%=txt_DateStart.ClientID%>").value.replace(/-/g, "/"));
switch (types) {
case "d":
StartDate = dateAdd('d', AddDate, EndDate);
break;
case "w":
StartDate = dateAdd('w', AddDate, EndDate);
break;
case "m":
StartDate = dateAdd('m', AddDate, EndDate);
break;
}
var m = StartDate.getMonth() + 1;
var time = StartDate.getFullYear() + "-" + (m < 10 ? '0' + m : m) + "-" + StartDate.getDate();
document.getElementById("<%=txt_DateStart.ClientID%>").value = time;
}
//日期增加函数
function dateAdd(strInterval, NumDay, dtTmp) {
if (dtTmp == null | dtTmp == "")
dtTmp = new Date();
switch (strInterval) {
case "h":
return new Date(Date.parse(dtTmp) + (3600000 * NumDay));
case "d":
return new Date(Date.parse(dtTmp) + (86400000 * (NumDay + 1)));
case "w":
return new Date(Date.parse(dtTmp) + ((86400000 * 7) * NumDay) + 86400000);
case "m":
return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + NumDay, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
case "y":
return new Date((dtTmp.getFullYear() + NumDay), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
}
}
</script>
<div>
<ul id="tags">
<li>
<asp:TextBox runat="server" ID="txt_DateStart" Text="2011-08-03"></asp:TextBox></li><li>
<asp:TextBox runat="server" ID="txt_DateEnd" Text="2011-08-09" onblur="setStartDate(-6)"></asp:TextBox></li></ul>
</div>