【问题标题】:Materializecss Date Picker only days in the pastMaterializecss 日期选择器仅过去几天
【发布时间】:2015-11-14 22:40:20
【问题描述】:

我正在尝试为用户的生日创建一个输入字段。为此,我希望他们只选择过去的年份。

我如何实现这一目标?我尝试在 selectYears 属性中输入负数,但没有成功。

JSFIDDLE

HTML:

<div class="col s12">
   <label for="birthday">Birthday</label>
   <input id="birthday" value="{{ user.birthday }}" type="date" name="birthday" class="datepicker">
</div>

JavaScript:

$('.datepicker').pickadate(
{
   selectMonths: true,
   selectYears: -100
});

【问题讨论】:

    标签: javascript html datepicker materialize


    【解决方案1】:
    var d = new Date();
    d.setFullYear( d.getFullYear() - 100 );
    $('.datepicker').pickadate(
    {
       selectMonths: true,
       selectYears: d,
       max: new Date()
    });
    

    这实际上会给出过去 100 年的完整列表。

    【讨论】:

    • 您可以将 selectYears 设置为 100 或 101,不需要前两行。最大值属性负责处理它。
    【解决方案2】:

    这是你设置年份的方式:

    var d = new Date();
    d.setFullYear( d.getFullYear() - 100 );
    $('.datepicker').pickadate(
    {
       selectMonths: true,
       selectYears: true,
       min: d,
       max: new Date()
    });
    

    http://jsfiddle.net/rpu61tf2/3/

    当您希望允许用户从下拉列表中选择年份时,您设置了 selectYears: true

    【讨论】:

    • 也许有些东西变了,到2008年你可以选择
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-02
    • 1970-01-01
    • 2016-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多