日历:从本周开始显示截至下一周的日期

时间:2016-08-27 06:06:34

标签: javascript jquery

你好朋友我有一个带有下一个按钮的日历当用户点击下一个按钮下周时间表将会再次出现用户点击什么都不会发生我希望显示截至下一周的日期

enter image description here

我的下一个按钮的JavaScript

function Next()
    {

    /*sunday*/
    var next_sunday = new Date(current_week.setDate(current_week.getDate() - current_week.getDay()+7));
    var sunday = [next_sunday.getDate()];
    var smonth = [next_sunday.getMonth() + 1] ;
    var syear = [next_sunday.getFullYear()];
    var sunday_date= syear + '-' + smonth + '-' + sunday;
    alert(sunday_date);
    document.getElementById("sunday").innerHTML =sunday;
    /*monday*/
    var next_monday = new Date(current_week.setDate(current_week.getDate() - current_week.getDay()+1));
    var monday = [next_monday.getDate()];
    var mmonth = [next_monday.getMonth() + 1] ;
    var myear = [next_monday.getFullYear()];
    var monday_date= myear + '-' + mmonth + '-' + monday;
    alert(monday_date);
    document.getElementById("monday").innerHTML =monday;

    /*Tuesday*/
    var next_tuesday = new Date(current_week.setDate(current_week.getDate() - current_week.getDay()+2));
    var tuesday = [next_tuesday.getDate()];
    var tmonth = [next_tuesday.getMonth() + 1] ;
    var tyear = [next_tuesday.getFullYear()];
    var tuesday_date= tyear + '-' + tmonth + '-' + tuesday;
    alert(tuesday_date);
    document.getElementById("tuesday").innerHTML =tuesday;
    /*Wednesday*/
    var next_wedday = new Date(current_week.setDate(current_week.getDate() - current_week.getDay()+3));
    var wednesday = [next_wedday.getDate()];
    var wmonth = [next_wedday.getMonth() + 1] ;
    var wyear = [next_wedday.getFullYear()];
    var wednesday_date= wyear + '-' + wmonth + '-' + wednesday;
    alert(wednesday_date);
    document.getElementById("wednesday").innerHTML =wednesday;
    /*Thursday*/
    var next_thuday = new Date(current_week.setDate(current_week.getDate() - current_week.getDay()+4)); 
    var thursday = [next_thuday.getDate()];
    var thmonth = [next_thuday.getMonth() + 1] ;
    var thyear = [next_thuday.getFullYear()];
    var thursday_date= thyear + '-' + thmonth + '-' + thursday;
    alert(thursday_date);
    document.getElementById("thursday").innerHTML =thursday;
    /*friday*/
    var next_friday = new Date(current_week.setDate(current_week.getDate() - current_week.getDay()+5));
    var friday = [next_friday.getDate()];
    var fmonth = [next_friday.getMonth() + 1] ;
    var fyear = [next_friday.getFullYear()];
    var friday_date= fyear + '-' + fmonth + '-' + friday;
    alert(friday_date);
    document.getElementById("friday").innerHTML =friday;
    /*saturday*/
    var next_satday = new Date(current_week.setDate(current_week.getDate() - current_week.getDay()+6));
    var saturday = [next_satday.getDate()];
    var samonth = [next_satday.getMonth() + 1] ;
    var sayear = [next_satday.getFullYear()];
    var saturday_date= sayear + '-' + samonth + '-' + saturday;
    document.getElementById("saturday").innerHTML =saturday;
    alert(saturday_date);
    $("#date").datepicker("setDate", new Date(next_monday));

    var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
    var week_month = months[next_satday.getMonth()] ;
    var week_year = [next_satday.getFullYear()];
    document.getElementById("endDate").innerHTML =week_month +' '+ saturday + ',' + ' ' + week_year;

    }

请提出建议

1 个答案:

答案 0 :(得分:0)

我得到了我用过的答案,如果其他循环首先我已经记录当前一周的最后一个日期意味着星期六的日期,然后与下周六进行比较

的Javascript

rect