【问题标题】:PHP counting months backwardPHP 倒数数月
【发布时间】:2015-09-12 03:20:57
【问题描述】:

我是新来的,有没有倒数 24 个月而不是 2 年的月份脚本?

    <?php
        $curYear = date(Y);
        $minYear = $curYear - 2;
     ?>

    <script type="text/javascript">
        jQuery(function($) {
            $('#child_birthday').datepicker({
              changeMonth: true,
              changeYear: true,
              yearRange: '<?php echo $minYear; ?>:<?php echo $curYear; ?>'
            });
        });
    </script>

【问题讨论】:

  • 嗨,如果我使用 2 年,日历允许选择一个可以追溯到 2013 年初的日期。如果我可以使用 24 个月,那么它不会允许在 9 月之前返回2013.

标签: php jquery jquery-ui


【解决方案1】:

要限制用户选择 9/2013 之前的日期,请使用 minDate 选项

http://api.jqueryui.com/datepicker/#option-minDate

 <?php
    $curYear = date('Y');
    $minYear = $curYear - 2;
    $curMonth = date('j');
 ?>

    jQuery(function($) {
        $('#child_birthday').datepicker({
          changeMonth: true,
          changeYear: true,
          minDate: new Date(<?php echo $minYear; ?>, <?php echo $curMonth ?> - 1, 1),
          yearRange: '<?php echo $minYear; ?>:<?php echo $curYear; ?>'
        });
    });

顺便说一句,你可以直接在javascript中计算当前年份和月份,所以不需要在php中计算并将结果传递给javascript。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 2014-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多