2012-02-21 104 views
0

我已經使用從http://keith-wood.name/datepick.html datepicker,這是偉大的。Jquery Datepicker定製年份

但我在控制年份範圍有問題。

這是我的代碼。

$('#date_executed').datepick({ 
dateFormat: 'MM dd, yy', 
yearRange:'2011:2012', 
showOn: 'both', 
buttonImageOnly: true, 
buttonText: 'Calendar', 
buttonImage: "images/calendar.gif" 
}); 

我需要添加2009年的名單,但我不想包括2010年。請幫助我謝謝。

回答

0

年份範圍更改爲yearRange:'2009:2012'然後取出2010上的負載,就像這樣:

$("select.datepick-month-year option[value$='2010']").remove(); 
+0

我已經做了某種形式的解決方案,除去2010年名單2009,2010,2011和2012 $('#date_executed')。click(function(){(datepick-new-year option))。each(function(){var_list_year =「2009, 2011,2012「; if(list_y ear!=「」) { var str = $(this).text();如果(list_year.search(str)== -1) {(this).hide(); } } }); }); 它的工作原理,但問題是,當我改變月份和年份的下拉列表時,它加載了2009,2010,2011,2012年份的列表。請幫助我很多謝謝。 – 2012-02-21 05:03:13

+0

感謝您的回答,但是當我更改月份和年份下拉菜單時,YearRange:'2009:2012再次生效 – 2012-02-21 05:17:21

0

你可以試試這個:

var yearRemoved = false; 

$(".ui-datepicker").on("mouseenter", function() { 

    if (!yearRemoved) { 
    yearRemoved = true;   
    $("select.datepick-month-year option[value$='2010']").remove(); 
    } 

});