2013-02-20 49 views
2

下面是我在我的应用程序&中使用的jQuery datepicker,它的运行效果很好。 现在的问题是我想将其限制在当前财年&这个我使用:使用DateFormat限制jQuery Datepicker到当前会计年度:'MM-dd'

maxDate: '03/30/2013' & minDate:'04/01/2012' 

但它不是与当前的日期格式的工作:“MM-YY”我使用&最差是我无法更改dateFormat。

var postForm = false; 
    $(function() { 
     $('.Month-Picker').datepicker({ 
      changeMonth: true, 
      changeYear: true, 
      showButtonPanel: false, 
      maxDate: '03/30/2013', 
      minDate:'04/01/2012', 
      dateFormat: 'MM-yy', 
      onChangeMonthYear: function() { postForm = true; }, 
      onClose: function (dateText, inst) { 
       var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val(); 
       var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val(); 
       $(this).datepicker('setDate', new Date(year, month, 1)); 
      }, 
      beforeShow: function (input, inst) { 
       if ((datestr = $(this).val()).length > 0) { 
        year = datestr.substring(datestr.length - 4, datestr.length); 
        month = jQuery.inArray(datestr.substring(0, datestr.length - 5), $(this).datepicker('option', 'monthNames')); 
        $(this).datepicker('option', 'defaultDate', new Date(year, month, 1)); 
        $(this).datepicker('setDate', new Date(year, month, 1)); 
        postForm = false; 
       } 
      } 
     }); 
    }); 

    $(document).ready(function() { 
     $("#aspnetForm").click(function() { 
      if (postForm == true) { 
       postForm = false; 
       var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val(); 
       var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val(); 
       $(this).datepicker('setDate', new Date(year, month, 1)); 
      } 
     }); 
    }); 

请帮我一把。

回答

0

您可以尝试使用下面的代码

$('#User_to_date').datepick({ 
     changeMonth: true, 
     changeYear: true, 
     showButtonPanel: false, 
     dateFormat: 'MM-yy', 
     onChangeMonthYear: function() { postForm = true; }, 
     onClose: function (dateText, inst) { 
      var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val(); 
      var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val(); 
      $(this).datepicker('setDate', new Date(year, month, 1)); 
     }, 
     beforeShow: function (input, inst) { 
      if ((datestr = $(this).val()).length > 0) { 
       year = datestr.substring(datestr.length - 4, datestr.length); 
       month = jQuery.inArray(datestr.substring(0, datestr.length - 5), $(this).datepicker('option', 'monthNames')); 
       $(this).datepicker('option', 'defaultDate', new Date(year, month, 1)); 
       $(this).datepicker('setDate', new Date(year, month, 1)); 
       postForm = false; 
      } 
     } 
    }); 

我测试用在我的项目的代码和“二月-21”的形式获取日期, 只改变一个日期选择器datepick