2012-04-26 40 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