jQueryUI DatePicker YearRange和ChangeYear问题

时间:2010-12-22 14:54:10

标签: javascript jquery jquery-ui datepicker jquery-ui-plugins

我在申请表上有一个日期选择器。我们仅允许出生日期在特定年龄范围内的申请。我启用了ChangeYear并将YearRange设置为“-65:-16”。我遇到的问题如下:

1 - 当我选择一个日期而没有先选择年份下拉菜单中的某些内容时,我会得到正确的月份和日期,但我将2016年作为一年。

2 - 尝试解决此问题我将YearRange设置为“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>

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

5 个答案:

答案 0 :(得分:19)

尝试使用当前年份的'c',如:

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

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

答案 1 :(得分:1)

检查defaultDate设置。当我将默认日期更改为指定年份范围之外(即“1-1-2016”)时,我只能看到您所描述的内容。您发布的代码中的其他所有内容都适用于我。

答案 2 :(得分:1)

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

这有效:

$('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' );

答案 3 :(得分:1)

尝试给出具有实际年份值的范围。 e.g。

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

他们也应该使用任何dateformat。

答案 4 :(得分:1)

尝试使用maxDate和minDate选项,如:

def startDowloadFromMagnet(self, magnet, outPath):
    """ Given a magnet link, start downloading file. Return true if start do not fail """

    try:
        self.activeTorrentList.append(lt.add_magnet_uri(self.ses, magnet, {'save_path': outPath}))    
        return True
    except:
        print '\n ERROR --> Wrong Magnet link: ' + str(magnet)
        return False



def pauseTorrentFromIndex(self, index):
    """ given a torrent index pause torrent """

    print 'isPaused(before): ' + str(self.isPaused(index)) #False
    self.activeTorrentList[index].pause(0)
    print 'isPaused(after): ' + str(self.isPaused(index)) #True 
    print 'Paused torrent which index: ' + str(index) #0        
    print 'Total num torrents: ' + str(self.getNumTorrents()) #1

def getTorrentFullInfo(self, index):
    """ Given a torrent index, return full torrent info"""
    #Download speed, status, size, ...

def isPaused(self, index):
    """ Return true if torrent is paused"""
    return self.activeTorrentList[index].status().paused