2016-01-20 65 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>