duankui1532 2011-09-16 18:21
浏览 27
已采纳

日历下拉错误

This should be quite simple but I can`t fix it :/

I am using a component that displays a list of months, the upcoming 12 to be exact. However, the year does not change to 2012 when past December.

See here: http://protekco.com/index.php/en/reservation.html

And the code that calls it:

        echo AHtml::getMonthsSelect('imonth', (int) $month, $year, $currentMonth, $currentYear, $config->calendarDeepMonth, 'onchange="Calendars.monthNavigation(this.value)"'); ?>

The $currentYear is the actual year variable that is presented on the site. I basically need someway to add +1 if we are past the end of the year. Any ideas?

Thanks!

Edit: here is the months array:

 function getMonthsSelect($name, $selectedMonth, $selectedYear, $month, $year, $deep, $attribs = '')
{
    $months = array(1 => JText::_('January') , 2 => JText::_('February') , 3 => JText::_('March') , 4 => JText::_('April') , 5 => JText::_('May') , 6 => JText::_('June') , 7 => JText::_('July') , 8 => JText::_('August') , 9 => JText::_('September') , 10 => JText::_('October') , 11 => JText::_('November') , 12 => JText::_('December'));

    $stop = $month + $deep;
    for ($i = $month; $i < $stop; $i ++)
        $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year)), ($months[$key] . '/' . $y));

    return JHTML::_('select.genericlist', $arr, $name, $attribs, 'value', 'text', $selectedMonth . ',' . $selectedYear);
}

Edit 3: Final solution:

function getMonthsSelect($name, $selectedMonth, $selectedYear, $month, $year, $deep, $attribs = '')
{
    $months = array(1 => JText::_('January') , 2 => JText::_('February') , 3 => JText::_('March') , 4 => JText::_('April') , 5 => JText::_('May') , 6 => JText::_('June') , 7 => JText::_('July') , 8 => JText::_('August') , 9 => JText::_('September') , 10 => JText::_('October') , 11 => JText::_('November') , 12 => JText::_('December'));

    $stop = $month + $deep;
    $wheremonth = 12 - $month;
    for ($i = $month; $i < $stop; $i ++, $wheremonth--)

    if ($wheremonth >= 0) {
        $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year)), ($months[$key] . '/' . $y));
        }
        else {            $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year+1)), ($months[$key] . '/' . $y));
        }
    return JHTML::_('select.genericlist', $arr, $name, $attribs, 'value', 'text', $selectedMonth . ',' . $selectedYear);

        }
  • 写回答

1条回答 默认 最新

  • douqiu1604 2011-09-16 18:33
    关注

    Not sure how the inputs are working here, but you have next month and previous month. You can implement a counter variable that adds when you hit next and subtracts when you hit previous. So something like:

    $i = 1;
    
    function datetracker() {
    
    if($nextbtnclicked = true) {
         $i++;
    } elseif($prevbtnclicked = true) {
         $i--;
    }
    
    if($i == 13) {
         $i = 1;
         $currentYear += 1;
    }
    }
    

    I'm just using sample variables, but you can implement the counter in the Javascript and do the login in JS.

    EDIT: That code actually looks right. Don't know why it's not working, but try something like this.

    function getMonthsSelect($name, $selectedMonth, $selectedYear, $month, $year, $deep, $attribs = '') 
    { 
        $months = array(1 => JText::_('January') , 2 => JText::_('February') , 3 => JText::_('March') , 4 => JText::_('April') , 5 => JText::_('May') , 6 => JText::_('June') , 7 => JText::_('July') , 8 => JText::_('August') , 9 => JText::_('September') , 10 => JText::_('October') , 11 => JText::_('November') , 12 => JText::_('December')); 
    
        $stop = $month + $deep;
        $newyear = false;
        for ($i = $month; $i < $stop; $i ++) {
    
            if($newyear) {
            $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year + 1)), ($months[$key] . '/' . $y));
             $newyear = false;
            } else {
            $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year)), ($months[$key] . '/' . $y));
    
            }
         if($i == 12) { $newyear = true; }
         }
    
        return JHTML::_('select.genericlist', $arr, $name, $attribs, 'value', 'text', $selectedMonth . ',' . $selectedYear); 
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。