2012-04-26 42 views
2

我正在使用修改(以下修改后的代码取自stackoverflow)jquery日历,但我想添加更多的过去几年,无法选择一天..在这个日历中请帮助我该怎么办?这个在HTML文件中使用修改后的剧本是这样的: -如何在jquery日历中添加更多年

<script> 
     $(document).ready(function() { 
     $(".datepicker").datepicker({ 
      changeMonth: true, 
      changeYear: true, 
      showButtonPanel: true, 
      dateFormat: 'dd MM yy', 
      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)); 
       } 
      } 
     }); 
     }); 
     </script> 
+0

欢迎堆栈溢出;请花些时间阅读[faq](http://stackoverflow.com/faq)。如果某人的回答已回答您的问题,请不要忘记点击其[答案]旁边的复选标记(http://meta.stackexchange.com/a/5235/171243)。 – 2012-04-26 07:55:21

回答

3

试试这个:

$(".datepicker").datepicker({ 
    yearRange: '1700:2050', 

年范围内为您提供了更多年

+0

谢谢JonathanRomer它的作品!!!!! – spsingh 2012-04-26 07:27:31