jQuery UI:Datepicker将年份范围下拉列表设置为100年 [英] jQuery UI: Datepicker set year range dropdown to 100 years

查看:440
本文介绍了jQuery UI:Datepicker将年份范围下拉列表设置为100年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用日期选择器的年份下拉列表默认情况下仅显示10年.用户必须单击最后一年才能添加更多年.

Using the Datepicker the year drop down by default shows only 10 years. The user has to click the last year in order to get more years added.

我们如何将初始范围设置为100年,以便用户默认情况下会看到一个很大的列表?

How can we set the initial range to be 100 years so that the user will see a large list by default?

    function InitDatePickers() {
        $(".datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true,
            maxDate: '@maxDate',
            minDate: '@minDate'
        });
    }

推荐答案

您可以在此处的每个文档中使用此选项设置年份范围

You can set the year range using this option per documentation here http://api.jqueryui.com/datepicker/#option-yearRange

yearRange: '1950:2013', // specifying a hard coded year range

或这种方式

yearRange: "-100:+0", // last hundred years

来自文档

默认:"c-10:c + 10"

Default: "c-10:c+10"

年份下拉列表中显示的年份范围:相对于今天的年份("-nn:+ nn"),相对于当前选定的年份("c-nn:c + nn"),绝对值( "nnnn:nnnn")或这些格式的组合("nnnn:-nn").请注意,此选项仅影响下拉菜单中显示的内容,使用minDate和/或maxDate选项来限制可以选择的日期.

The range of years displayed in the year drop-down: either relative to today's year ("-nn:+nn"), relative to the currently selected year ("c-nn:c+nn"), absolute ("nnnn:nnnn"), or combinations of these formats ("nnnn:-nn"). Note that this option only affects what appears in the drop-down, to restrict which dates may be selected use the minDate and/or maxDate options.

这篇关于jQuery UI:Datepicker将年份范围下拉列表设置为100年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆