2016-01-20 63 views
0

我需要在初始化後更改datepicker的年份範圍。我有datpickerJquery Datepicker在初始化後更改年份範圍

$(function() { 
    $("#datepicker").datetimepicker({ 
     showOn: "button", 
     buttonText: "Date Selector", 
     buttonImage: "calendar.png", 
     buttonImageOnly: true, 
     dateFormat: "dd M yy", 
     timeFormat: "h:mm TT", 
     changeMonth: true, 
     yearRange: '1900:+10', 
     changeYear: true 
    }); 
}); 


<p>Date: <input type="text" id="datepicker"></p> 

我需要更改年份範圍不改變通用代碼的通用代碼,所以只在一個地方的範圍內變化。 因此,在通過通用代碼初始化之後,將更改爲2015年:2016年。 有什麼幫助嗎?

+0

創建的你有什麼至今一個jsfiddle.net。 – BenG

+0

哦,只是fyi,無論何時您使用插件發佈有關代碼的問題,請嘗試並參考您使用的插件。 – SpYk3HH

回答

0

我知道你正在使用的日期時間選擇器插件,但如果它是一個我想是的,它只是一個擴展jQueryUI的的日期選擇器,爲此下面應該努力改變年範圍

$("#datepicker").datepicker("option", "yearRange", "2002:2012"); 

$(function() { 
 
    $("#datepicker").datepicker({ 
 
     showOn: "button", 
 
     buttonText: "Date Selector", 
 
     //buttonImage: "calendar.png", 
 
     buttonImageOnly: true, 
 
     dateFormat: "dd M yy", 
 
     timeFormat: "h:mm TT", 
 
     changeMonth: true, 
 
     yearRange: '1900:+10', 
 
     changeYear: true 
 
    }); 
 
}); 
 

 
$('button').click(function(e) { 
 
    
 
    /* L I K E T H I S */ 
 
    $("#datepicker").datepicker("option", "yearRange", "2015:2016"); 
 
    /* L I K E T H I S */ 
 
    
 
    $(this).fadeOut(); 
 
});
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> 
 

 

 
<p>Date: <input type="text" id="datepicker"></p> 
 

 
<button>change range</button>