我在申请表上有一个datepicker。我们仅允许出生日期在一定年龄范围内的应用。我启用了更改,并将年度设置为“ -65:-16”。我遇到的问题如下:

1-当我在不首先选择某些内容的下拉列表中选择日期时,我会得到正确的月和一天,但我获得了2016年的一年。

2-试图解决此问题,我将年度设置为“ n-65:n-16”。这导致年份下拉阶段仅显示当年(2010年)。即使是怪异的是,如果您选择一个日期,您仍然可以获得正确的月份和日期以及2016年。

这是我用来设置datepicker的代码:

    <script type="text/javascript">
    $(document).ready(function (e) {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

        function EndRequestHandler(sender, args) {
            $(function () {
                $("#DateOfBirth").datepicker({ yearRange: '-65:-13', changeMonth: true, changeYear: true, defaultDate: '1-1-1994', dateFormat: 'mm-dd-yy' })
            });
        }

        $(function () {
            $("#DateOfBirth").datepicker({ yearRange: '-65:-13', changeMonth: true, changeYear: true, defaultDate: '1-1-1994', dateFormat: 'mm-dd-yy' })
        });
    });
</script>

我希望这是我做错了的事情,有人可以告诉我那是什么。谢谢你的帮助。

有帮助吗?

解决方案

尝试在本年度使用“ C”:

$('.datepicker').datepicker({changeYear: true, yearRange : 'c-65:c+10'});

有关更多信息查看 http://api.jqueryui.com/datepicker/#option areRange

其他提示

检查您的默认设置。当我将默认日期更改为指定年度范围之外的事物(即1-1-1-2016')时,我只能看到您要描述的内容。您发布的代码中的其他所有内容都为我工作。

也偶然发现了这一点。我没有进一步研究,但是呼叫顺序似乎有所作为。

这起作用:

$('DIV#startdate').datepicker( 'option', { dateFormat: 'yy-mm-dd' } );
$('DIV#startdate').datepicker( 'setDate', '10-09-11' );
$('DIV#startdate').datepicker( 'option', { changeYear: true } );

这仅显示2010年的年度列表框:

$('DIV#startdate').datepicker( 'option', { dateFormat: 'yy-mm-dd' } );
$('DIV#startdate').datepicker( 'option', { changeYear: true } );
$('DIV#startdate').datepicker( 'setDate', '10-09-11' );

尝试以实际年度值给出范围。例如

$('.datepicker').datepicker({changeYear: true, yearRange : '1990:2010'})

他们还应该与任何dateformat合作。

尝试使用MaxDate和Mindate选项,例如:

$(document).ready(function () {
    $("#datepicker").datepicker({
        yearRange: '-65:-13',
        changeMonth: true,
        changeYear: true,
        defultDate: '1-1-1994',
        dateFormat: 'mm-dd-yy',
        minDate:"-65Y",
        maxDate:"-13Y" 
    });
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top