1

わかりましたので、ここで見られるようにPHPカレンダークラスを作成した取引がありますhttp://pastebin.com/QERgmn8yまた、ここで見られるように、特定の条件が満たされた場合にカレンダーの日付と年を切り替える ajax スクリプトを持っていますhttp: //pastebin.com/kfrmz79J

まだ十分なレポテーションがないので、ここに PasteBin の最終スクリプトの ID があります。ID はJKdi6H8f です。このスクリプトですべてが実現します。

これまでのところ、次のような複数の条件を試しました

if(prevMon > mon ){//set year to -1};

if(nextMon < mon){//set year to +1};

および他の多くの条件が、これまでのところ最もうまく機能しているように見えましたが、唯一の問題は、日付を12月に切り替えてから戻ると1年上がるか、12月になったら1月に切り替えて12月に戻ることです.年は 1 つ戻るのではなく、2014 年のままになります。

誰かがこの問題の解決策を見つけることができれば、私はとても助かります。

関連するコードのスニペットもここにあります

 //next month is clicked
        $(document).on('click',"#next_month", function(){
                var selected =$(this).attr('class');
                date.setMonth(selected-1);
                var mon = date.getMonth();
                var prevMon = date.getMonth()-1;
                if(prevMon < 0){
                        prevMon = 11;
                }
                var nextMon = date.getMonth()+1;
                if(nextMon > 11){
                        nextMon = 0;
                }
                var remain = 11 - mon;
                var currY = date.getFullYear();
                console.log(selected+"current m: "+mon+" prev m: "+prevMon+" next m: "+nextMon+" current y: "+currY+" remainder: "+remain);

                if(remain == 0){
                        date.setFullYear(currY+1);
                        console.log(currY);
                }
                $.ajax({
                        type: "POST",
                        url: "calendar/calendar.php",
                        data: {nMonth: selected, year: currY},
                        success: function(data){
                                var d = data.split("▼");
                                $("#cal_wrap").html(d[1]);
                                $("#cal_header_wrap").html(d[0]);
                        }
                });
        });

        //previous month is clicked
        $(document).on('click',"#prev_month", function(){
                var selected =$(this).attr('class');
                date.setMonth(selected-1);
                var mon = date.getMonth();
                var prevMon = date.getMonth()+1;
                if(prevMon > 11){
                        prevMon = 0;
                }
                var nextMon = date.getMonth()-1;
                if(nextMon < 0){
                        nextMon = 11;
                }
                var remain = 11 - mon;
                var currY = date.getFullYear();
                console.log(selected+"current m: "+mon+" prev m: "+prevMon+" next m: "+nextMon+" current y: "+currY+" remainder: "+remain);

                if(remain == 11){
                        date.setFullYear(currY-1);
                        console.log(currY);
                }
                $.ajax({
                        type: "POST",
                        url: "calendar/calendar.php",
                        data: {pMonth: selected, year: currY},
                        success: function(data){
                                var d = data.split("▼");
                                $("#cal_wrap").html(d[1]);
                                $("#cal_header_wrap").html(d[0]);
                        }
                });
        });

そしてPHPスクリプト

if(isset($nMonth)){
                //sets the year to what javascript returns
                $cal->setY($year);
                $nm = mktime(0,0,0,$nMonth,1,$cal->getY(),0);
                $month = date("m",$nm);
                $cal->setM($month);
                $cal->showCalHeader();
                echo "▼";
                $cal->showWeek();
                $cal->showCalendar();
        }else if(isset($pMonth)){
                //sets the year to what javascript returns
                $cal->setY($year);
                //sets the month to previous month
                $pm = mktime(0,0,0,$pMonth,1,2013,0);
                $month = date("m",$pm);
                $cal->setM($month);
                $cal->showCalHeader();
                echo "▼";
                $cal->showWeek();
                $cal->showCalendar();  
        }
4

0 に答える 0