📅  最后修改于: 2023-12-03 15:01:10.726000             🧑  作者: Mango
HTML Form Date is a user interface element that allows a user to select a date from a calendar. Using this input type, you can limit the range of selectable dates. This can be really helpful when you want to restrict the options a user has to choose from, for instance, when selecting a date of birth, or dates for a reservation.
The syntax for the input type is as follows:
<input type="date" name="date" id="date" min="yyyy-mm-dd" max="yyyy-mm-dd">
Here,
type="date"
specifies the type of input element we want.name="date"
specifies the name of the input field.id="date"
specifies the id of the input field.min
and max
attributes are used to specify the minimum and maximum dates the user can select respectively.Here is an example of how to use the HTML form date input type with the min and max attributes set:
<label for="reservation-date">Select a date for reservation:</label>
<input type="date" id="reservation-date" name="reservation-date" min="2022-01-01" max="2022-12-31">
In this example, the user can only select a date between 1st January 2022 and 31st December 2022.
HTML Form Date input type is supported by almost all modern web browsers, including Google Chrome, Mozilla Firefox and Safari. However, older versions of Internet Explorer do not support this input type.
HTML Form Date input type is a great way to collect date input from users with a limited range of selectable dates. By using the min and max attributes, you can control the range of dates available for selection. It is important to note that not all web browsers support this input type, so you should always provide an alternative input method for users who do not have a compatible browser.