2013-05-08 134 views
1

我开发的MVC应用程序,我在它使用日期选择器。 我想1930年的范围内设定为1995年的日期选择器。 我想设置选定的日期是1995年1月1日如何在的DateTimePicker日期范围选择默认的日期?

我写了下面的代码。

$(document).ready(function() { 


     $(function() { 
      $('.BirthDate').datepicker({ 
       dateFormat: "dd-M-y", 
       yearRange:'1930:1995', 
       buttonImage: '@Url.Content("~/Resource/Calender.jpg")', 
       buttonImageOnly: true 
      }); 
     }); 

     $(".BirthDate").datepicker("setDate", "01/01/1995"); 
     }); 

但它不工作... 我必须做出什么改变?

回答

3

使用defaultDate选项:

通过指定Date对象或为当前dateFormat字符串为实际的日期。 http://api.jqueryui.com/datepicker/#option-defaultDate

$(document).ready(function() { 
    $('.BirthDate').datepicker({ 
     dateFormat: "dd-M-y", 
     yearRange:'1930:1995', 
     buttonImage: '@Url.Content("~/Resource/Calender.jpg")', 
     buttonImageOnly: true, 
     defaultDate: '01-Jan-95', 
     maxDate: '31-Dec-95' 
    }); 
}); 

工作例如:http://jsfiddle.net/VkZrP/2/

+0

NOP,这是正确的地方,我已经把代码的setDate? – bnil 2013-05-08 07:57:16

+0

是的,但你可以做到这一点也在例子我张贴。 – 2013-05-08 07:57:37

+0

不,它在年份框中显示1930年。 – bnil 2013-05-08 08:01:16