我有 3 个按钮,即一周,上一个和下一个。单击星期按钮时,它将显示在文本框中选择的日期并添加 6 天(for example 26 Jun 2013-2 Jul 2013 )
。单击上一个按钮时,它将19 Jun 2013-26 Jun 2013
在文本框中显示。单击下一个按钮时,它将显示2 Jul 2013-8 Jul 2013
在文本框中。这个过程还在继续。我想知道这将如何完成javascript
。
enter code here
<input type="text" id="txtdatetimeshow" readonly="readonly"
style="height: 25px; width: 150px;
font-size: medium; font-family: Times New Roman;" runat="server" />
<input type="button" id="showweekbtn" runat="server" value="week"/>
<input type="button" id="sfprevbtn" runat="server" value="prev"/>
<input type="button" id="sfnextbtn" runat="server" value="next"/>
<script type="text/javascript">
$(document).ready(function()
{
var today=new Date();
var date=today.getDate();
var month=today.getMonth();
var year= today.getFullYear();
var month_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec");
var NextDate= new Date(year, month, date);//today's date
var weekdate=new Date(NextDate);
weekdate.setDate(weekdate.getDate()+6);//add 6 days to the date
var Ndate=NextDate.getDate()+" "+month_names[month]+" "+NextDate.getFullYear()+"-"+" "+weekdate.getDate()+" "+month_names[weekdate.getMonth()]+" "+weekdate.getFullYear();
var nextWeekDate=new Date(weekdate);
nextWeekDate.setDate(weekdate.getDate()+6);
var NWdate=weekdate.getDate()+" "+month_names[weekdate.getMonth()]+" "+weekdate.getFullYear()+"-"+""+nextWeekDate.getDate()+" "+month_names[nextWeekDate.getMonth()]+" "+nextWeekDate.getFullYear();
var prevWeekDate=new Date(NextDate);
prevWeekDate.setDate(NextDate.getDate()-6);//subtract 6 days to date
var PWdate=prevWeekDate.getDate()+" "+month_names[prevWeekDate.getMonth()]+" "+prevWeekDate.getFullYear()+"-"+NextDate.getDate()+" "+month_names[NextDate.getMonth()]+" "+NextDate.getFullYear();
//to show previous date
$("#sfprevbtn").click(function()
{
var prevDate=new Date(year,month,date-1);
var pdate=prevDate.getDate()+" "+month_names[month] +" "+prevDate.getFullYear();
$("#txtdatetimeshow").val(PWdate);
});
//to show next date
$("#sfnextbtn").click(function()
{
var nextDate=new Date(year,month,date+1);
var Ndate=nextDate.getDate()+" "+month_names[month] +" "+nextDate.getFullYear();
$("#txtdatetimeshow").val(NWdate);
});
//to show week view
$("#showweekbtn").click(function()
{
$("#txtdatetimeshow").val(Ndate);
});
});
</script>