出生日期文本框的Datepicker插件

Hen*_*wan 14 jquery datepicker jquery-plugins

我发现了一个非常容易使用的名为jquery datepicker的日期选择器.但问题是我想把它用于出生日期.例如:我的出生年份是1986年,当年是2013年,那么我需要多次点击左箭头才能减少几个月,直到我找到1986年.如果我的出生年份是1960年或以下,那将会更麻烦.

有没有人知道任何适合这个的datepicker插件?也许可以从Dropbox中选择哪个年份或月份的日期选择器?

EL *_*bov 19

简而言之:您可以通过演示页面中的Restricting Datepicker部分来实现.

如果你向下看一下演示页面 ,你会看到一个"限制日期选择器"部分.使用下拉列表指定" Year dropdown shows last 20 years"演示,然后点击查看源:

$("#restricting").datepicker({ 
    yearRange: "-20:+0", // this is the option you're looking for
    showOn: "both", 
    buttonImage: "templates/images/calendar.gif", 
    buttonImageOnly: true 
});
Run Code Online (Sandbox Code Playgroud)

你会想这样做(显然改变-20-100什么的).

选项#2:正在使用api 的changeMonthchangeYear选项.

尝试在当年使用'yy',如:

$('.datepicker').datepicker({changeYear: true, yearRange : 'yy-50:yy+1'});
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请查看http://api.jqueryui.com/datepicker/#option-yearRange


Cas*_*ton 9

我遇到了同样的问题,所以如果其他人遇到同样的问题,我想我会发布解决方案.这是在上面的答案,但你必须阅读评论,以获得所有这些.

在头部:

<script src="~/Scripts/jquery-1.10.2.js"></script>

<script>
    $(function () {
        $("#datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            yearRange: '-100:+0'
        });
    });
</script>
Run Code Online (Sandbox Code Playgroud)

在HTML中:

<input type="text" class="form-control" id="datepicker">
Run Code Online (Sandbox Code Playgroud)

这将为您提供一个日期选择器,其中月份是自己的下拉菜单,年份是自己的下拉菜单,年份从今天开始,可以追溯到100年.