You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Materialize日期选择器的起始年份(设置为1990年)

How to Set Materialize CSS Datepicker Starting Year to 1990

Hey there! To set your Materialize CSS Datepicker's starting year to 1990, you just need to add a configuration object when initializing the datepicker. Here are two straightforward approaches you can use:

Option 1: Use yearRange to Define Year Scope

This option controls the range of years displayed in the datepicker's year selector. You can set the start year as 1990 and pair it with the current year (or a fixed end year) to keep it relevant:

Updated JavaScript Code

$(document).ready(function(){
  $('.datepicker').datepicker({
    // Set start year to 1990, end year to current year
    yearRange: [1990, new Date().getFullYear()]
  });
});

If you want a fixed end year instead (e.g., 2025), just replace new Date().getFullYear() with your desired year:

yearRange: [1990, 2025]

Option 2: Use minDate to Restrict Earliest Selectable Date

If you want to prevent users from selecting any date before 1990 entirely, use the minDate option to set the earliest allowed date to January 1st, 1990 (note: months in JavaScript are 0-based, so January is 0):

Updated JavaScript Code

$(document).ready(function(){
  $('.datepicker').datepicker({
    minDate: new Date(1990, 0, 1)
  });
});

Your HTML Remains Unchanged

You don't need to modify your existing HTML code:

<input type="text" class="datepicker">

Pick the option that best fits your use case—either controlling the visible year range or locking down the earliest selectable date!

内容的提问来源于stack exchange,提问作者user8477089

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:20:26