duandingcu7010 2014-08-26 14:37
浏览 18
已采纳

PHP / JQuery逐步完成了几个月的列表

I'm trying to display a single entry of the current month & year which has an up / down arrow that allows you to move to the next or previous month / year.

Using PHP I've created a UL list from two arrays (months & years) that contains all of the entries I need, but now I can't figure out how to display a single entry that can step back or forth through the list. Any suggestions on where to look with JQuery?

The PHP is:

$month_list = array('JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC');
$year_list = array('2014', '2015', '2016', '2017', '2018', '2019', '2020');

for ($years=0; $years!=count($year_list); $years++) {
   for ($months=0; $months!=count($month_list); $months++) {    
        echo '<li class="cal_month" >'.$month_list[$months].
             '<div class="year">'.$year_list[$years].'</div></li>';
    }
}
  • 写回答

1条回答 默认 最新

  • donglvhe7591 2014-08-26 14:52
    关注

    Yes, have an HTML like that :

    <span id="curr-month">JAN</span> <span id="curr-year">2014</span>
    <a href="#" class="changer" data-target="month">month change</a>
    <a href="#" class="changer" data-target="year">year change</a>
    

    Have your arrays in jQuery:

    $('body').on('click', '.changer', function(e){
      var target = $(this).data('target');
      var dates = {
            month: ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'],
            year: ['2014', '2015', '2016', '2017', '2018', '2019', '2020']
          },
          index = dates[target].indexOf($('#curr-'+target).text());
      var toIndex = (index >= dates[target].length - 1 ) ? 0 : index + 1;
      $('#curr-'+target).text(dates[target][toIndex]);
    
    });
    

    Here's a fiddle : http://jsfiddle.net/kbfj9nwf/1/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳