问答详情
源自:5-3 点击选择

当月份到了一月份,再往前,怎么年分不变

不会写呀,日历不对


提问者:武慕林 2017-05-27 20:57

个回答

  • 慕侠9445594
    2018-07-27 23:51:55

    if(direction === 'prev'){

                if(month <= 1){

                    console.log('ppp')

                    month =12

                    year--

                }else{

                    month--

                }

            }

            if(direction === 'next'){

                if(month >11){

                    month =1

                    year++

                }else{

                    month++

                }

            }

    渲染部分可以这么写

  • jiuwei
    2017-05-28 18:24:11

    切换上一月时,可以这样写:

    if(direction === 'prev') {

      month--;

      if(month === 0){

      month = 12;

      year--;

      }

      }