How to hide the year part in Html <input type=“date”> calendar panel?

◇◆丶佛笑我妖孽 提交于 2019-12-02 04:47:40

问题


Is there any way to hide the year part html calendar panel, only show month and day part on the calendar.


回答1:


Unfortunately there's no easy answer, however you can use an alternative method to force the user to enter only month and date by using javascript.

var year = new Date().getFullYear();
document.getElementById('date').setAttribute("min", year + "-01-01");
document.getElementById('date').setAttribute("max", year + "-12-31");
<input type='date' id='date' />

The above code locks the year to current year, so the user will only be able to enter the month and the date.


If you still want to try the hard way, read these articles

  • jquery ui datepicker day/month only, not year selection
  • jQuery UI - Datepicker - Hide year
  • Jquery datepicker - only day and month


来源:https://stackoverflow.com/questions/48680414/how-to-hide-the-year-part-in-html-input-type-date-calendar-panel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!