• 利用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);

                } 

    };

  • 相关阅读:
    Scrapy的架构与原理的理解【转】
    Scrapy框架的命令行详解【转】
    WPF 程序中启动和关闭外部.exe程序
    C++ 二维数组(双重指针作为函数参数)
    C++ 遇见的一些函数
    C++ #pragma 预处理指令
    C++异常处理(Exception Handling)
    C++模板学习随笔
    C++ 数组的地址问题学习随笔
    关于C++几个容易混淆的概念总结
  • 原文地址:https://www.cnblogs.com/xinbaba/p/6381638.html
Copyright © 2020-2023  润新知