PHP向后数月

时间:2015-09-12 03:20:58

标签: php jquery jquery-ui

我是新来的,是否有月份脚本向后计算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>

1 个答案:

答案 0 :(得分:0)

要限制用户选择2013年9月之前的日期,请使用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。