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

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

问题描述

使用 Datepicker 时,年份下拉菜单默认只显示 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'
        });
    }

推荐答案

您可以根据此处的文档使用此选项设置年份范围 http://api.jqueryui.com/datepicker/#option-yearRange

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天全站免登陆