• 利用JS实现点击上一周或下一周却换


    1.页面加载显示当前年份的第几周

     效果如图:

    html代码:

      <font size="2" color="black">
         <input id="btnweek5" type="button" class="btn" value="上周" onclick="EduCommission.GetLastWeek()" />
          <span id="year"></span><span>第</span><span id="week"></span><span>周</span>
          <input id="btnweek6" type="button" value="下周" class="btn" onclick="EduCommission.GetNextWeek()" />
      </font>

    JS代码:

        var date = new Date();
        nowyear = date.getFullYear();
        nowweek = EduCommission.TheWeek(date);
        $("#year").text(nowyear);
        $("#week").text(nowweek - 1);

      

    //本周 EduCommission.TheWeek = function (now) {

        var totalDays = 0;    

        var years = now.getYear();

        if (years < 1000)  

           years += 1900;   

      var days = new Array(12);   

       days[0] = 31;   

       days[2] = 31;  

       days[3] = 30;  

       days[4] = 31;   

       days[5] = 30;   

       days[6] = 31;  

       days[7] = 31;  

       days[8] = 30;  

       days[9] = 31;  

       days[10] = 30;

        days[11] = 31;

        if (Math.round(now.getYear() / 4) == now.getYear() / 4)

        {  days[1] = 29;     }

        else { days[1] = 28;}  

       if (now.getMonth() == 0)

         {  

           totalDays = totalDays + now.getDate(); 

         }

      else {  

           var curMonth = now.getMonth();

           for (var count = 1; count <= curMonth; count++) {  

           totalDays = totalDays + days[count - 1];         }  

           totalDays = totalDays + now.getDate();     }    

          var week = Math.round(totalDays / 7) + 1;    

          return week; }

     2.点击上一周或下一周时:

    //点击上一周

    EduCommission.GetLastWeek = function () {   

    var y = $("#year").text();

        var week = $("#week").text();

        if (week == 1) {

            $("#year").text(y - 1);

            var strdate = y - 1 + "-12-31";

            var date = new Date(Date.parse(strdate.replace(/-/g, "/")));

            var lastyearweek = EduCommission.TheWeek(date);

            $("#week").text(lastyearweek);     }    

       else {        

          $("#week").text(week - 1);

         }  };

    //点击下一周

    EduCommission.GetNextWeek = function () {

        var y = $("#year").text();  

        var week = $("#week").text();

        if (y < nowyear) {

            var strdate = y + "-12-31";

            var date = new Date(Date.parse(strdate.replace(/-/g, "/")));              

            var weekcount = EduCommission.TheWeek(date);

            if (week == weekcount) {

                $("#year").text(parseInt(y) + 1);

                $("#week").text(1);

                }

           else {

                $("#week").text(parseInt(week) + 1);  

                 }

          else {

            $("#week").text(parseInt(week) + 1);

                } 

    };

  • 相关阅读:
    Queueing at Bank【PAT 1017题】
    table标签的布局
    股票投资的24堂必修课1
    股票投资的24堂必修课2基本面分析
    Eclipse最全快捷键 分享便捷与快乐
    浅析将matlab函数编译成dll供Cpp调用的方法
    Python编程语言中调用Matlab绘制保存数据的方案
    Eclipse中10个最有用的快捷键组合
    WPF 4 DataGrid 控件(进阶篇二)
    VBS 操作 IIS
  • 原文地址:https://www.cnblogs.com/xinbaba/p/6381638.html
Copyright © 2020-2023  润新知