для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

Для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

elements of type=»date» create input fields that let the user enter a date, either with a textbox that validates the input or a special date picker interface.

The resulting value includes the year, month, and day, but not the time. The time and datetime-local input types support time and date+time input.

Value

A DOMString representing the date entered in the input. The date is formatted according to ISO8601, described in Format of a valid date string in Date and time formats used in HTML.

You can set a default value for the input with a date inside the value attribute, like so:

You can get and set the date value in JavaScript with the HTMLInputElement value and valueAsNumber properties. For example:

Additional attributes

Along with the attributes common to all elements, date inputs have the following attributes.

If both the max and min attributes are set, this value must be a date string later than or equal to the one in the min attribute.

If both the max and min attributes are set, this value must be a date string earlier than or equal to the one in the max attribute.

A string value of any means that no stepping is implied, and any value is allowed (barring other constraints, such as min and max ).

Note: When the data entered by the user doesn’t adhere to the stepping configuration, the user agent may round to the nearest valid value, preferring numbers in the positive direction when there are two equally close options.

For date inputs, the value of step is given in days; and is treated as a number of milliseconds equal to 86,400,000 times the step value (the underlying numeric value is in milliseconds). The default value of step is 1, indicating 1 day.

Note: Specifying any as the value for step has the same effect as 1 for date inputs.

Using date inputs

Date inputs sound convenient β€” they provide an easy interface for choosing dates, and they normalize the data format sent to the server regardless of the user’s locale. However, there are currently issues with because of its limited browser support.

Note: Hopefully, over time browser support will become ubiquitous, and this problem will fade away.

Basic uses of date

Setting maximum and minimum dates

You can use the min and max attributes to restrict the dates that can be chosen by the user. In the following example, we set a minimum date of 2017-04-01 and a maximum date of 2017-04-30 :

The result is that only days in April 2017 can be selected β€” the month and year parts of the textbox will be uneditable, and dates outside April 2017 can’t be selected in the picker widget.

Note: You should be able to use the step attribute to vary the number of days jumped each time the date is incremented (e.g. to only make Saturdays selectable). However, this does not seem to be in any implementation at the time of writing.

Controlling input size

Validation

By default, doesn’t validate the entered value beyond its format. The interfaces generally don’t let you enter anything that isn’t a date β€” which is helpful β€” but you can leave the field empty or enter an invalid date in browsers where the input falls back to type text (like the 32nd of April).

If you use min and max to restrict the available dates (see Setting maximum and minimum dates), supporting browsers will display an error if you try to submit a date that is out of bounds. However, you’ll need to double-check the submitted results to ensure the value is within these dates, if the date picker isn’t fully supported on the user’s device.

You can also use the required attribute to make filling in the date mandatory β€” an error will be displayed if you try to submit an empty date field. This should work in most browsers, even if they fall back to a text input.

Let’s look at an example of minimum and maximum dates, and also made a field required:

If you try to submit the form with an incomplete date (or with a date outside the set bounds), the browser displays an error. Try playing with the example now:

Here’s the CSS used in the above example. We make use of the :valid and :invalid pseudo-elements to add an icon next to the input, based on whether or not the current value is valid. We had to put the icon on a next to the input, not on the input itself, because in Chrome at least the input’s generated content is placed inside the form control, and can’t be styled or shown effectively.

Warning: Client-side form validation is no substitute for validating on the server. It’s easy for someone to modify the HTML, or bypass your HTML entirely and submit the data directly to your server. If your server fails to validate the received data, disaster could strike with data that is badly-formatted, too large, of the wrong type, etc.

Handling browser support

As mentioned, the major problem with date inputs is browser support.

Unsupporting browsers gracefully degrade to a text input, but this creates problems in consistency of user interface (the presented controls are different) and data handling.

One way around this is the pattern attribute on your date input. Even though the date picker doesn’t use it, the text input fallback will. For example, try viewing the following in a unsupporting browser:

If you submit it, you’ll see that the browser displays an error and highlights the input as invalid if your entry doesn’t match the pattern ####-##-## (where # is a digit from 0 to 9). Of course, this doesn’t stop people from entering invalid dates, or incorrect formats. So we still have a problem.

At the moment, the best way to deal with dates in forms in a cross-browser way is to have the user enter the day, month, and year in separate controls, or to use a JavaScript library such as jQuery date picker.

Examples

In this example, we create 2 sets of UI elements for choosing dates: a native picker and a set of 3 elements for older browsers that don’t support the native date input.

The HTML looks like so:

The months are hardcoded (as they are always the same), while the day and year values are dynamically generated depending on the currently selected month and year, and the current year (see the code comments below for detailed explanations of how these functions work.)

JavaScript

Note: Remember that some years have 53 weeks in them (see Weeks per year)! You’ll need to take this into consideration when developing production apps.

Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

Для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

Π­Π»Π΅ΠΌΠ΅Π½Ρ‚Ρ‹ Ρ‚ΠΈΠΏΠ° date ΡΠΎΠ·Π΄Π°ΡŽΡ‚ поля Π²Π²ΠΎΠ΄Π° ΠΈ ΠΏΠΎΠ·Π²ΠΎΠ»ΡΡŽΡ‚ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŽ ввСсти Π΄Π°Ρ‚Ρƒ, Π»ΠΈΠ±ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ text box для автоматичСской ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ ΠΊΠΎΠ½Ρ‚Π΅Π½Ρ‚Π° ΠΈΠ»ΠΈ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ ΡΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹ΠΉ интСрфСйс date picker. Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ Π²ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ Π³ΠΎΠ΄, мСсяц, дСнь, Π½ΠΎ Π½Π΅ врСмя. Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ поля Π²Π²ΠΎΠ΄Π° time (en-US) ΠΈΠ»ΠΈ datetime-local, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π²Π²ΠΎΠ΄ΠΈΡ‚ΡŒ врСмя ΠΈΠ»ΠΈ Π΄Π°Ρ‚Ρƒ+врСмя соотвСтствСнно.

Π˜ΡΡ…ΠΎΠ΄Π½Ρ‹ΠΉ ΠΊΠΎΠ΄ этого ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠ³ΠΎ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π° хранится Π² Ρ€Π΅ΠΏΠΎΠ·ΠΈΡ‚ΠΎΡ€ΠΈΠΈ GitHub. Если Π²Ρ‹ Ρ…ΠΎΡ‚ΠΈΡ‚Π΅ внСсти свой Π²ΠΊΠ»Π°Π΄ Π² ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½Ρ‹Ρ… ΠΏΡ€ΠΈΠΌΠ΅Ρ€ΠΎΠ², поТалуйста, ΠΊΠ»ΠΎΠ½ΠΈΡ€ΡƒΠΉΡ‚Π΅ https://github.com/mdn/interactive-examples ΠΈ ΠΎΡ‚ΠΏΡ€Π°Π²ΡŒΡ‚Π΅ Π½Π°ΠΌ запрос Π½Π° внСсСниС ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ.

Π‘Ρ€Π΅Π΄ΠΈ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€ΠΎΠ² со своим интСрфСйсом для Π²Ρ‹Π±ΠΎΡ€Π° Π΄Π°Ρ‚Ρ‹, Π΅ΡΡ‚ΡŒ интСрфСйс Π±Ρ€Π°ΡƒΠ·Π΅Ρ€ΠΎΠ² Chrome ΠΈ Opera, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ выглядит Ρ‚Π°ΠΊ:

для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π€ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

Π’ Edge ΠΎΠ½ выглядит Ρ‚Π°ΠΊ:

для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π€ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

А Π² Firefox выглядит Ρ‚Π°ΠΊ:

для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π€ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅

Π’Ρ‹ Ρ‚Π°ΠΊΠΆΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚Π΅ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ ΠΈΠ»ΠΈ ΡƒΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚ΡŒ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ Π΄Π°Ρ‚Ρ‹ Π² JavaScript с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ свойств value ΠΈ valueAsNumber элСмСнта input. НапримСр:

Π”ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Ρ‹

ΠΡ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠžΠΏΠΈΡΠ°Π½ΠΈΠ΅
maxМаксимально возмоТная Π΄Π°Ρ‚Π° для установки
minМинимально возмоТная Π΄Π°Ρ‚Π° для установки
stepΠ¨Π°Π³ (Π² днях), с ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΌ Π±ΡƒΠ΄Π΅Ρ‚ ΠΈΠ·ΠΌΠ΅Π½ΡΡ‚ΡŒΡΡ Π΄Π°Ρ‚Π° ΠΏΡ€ΠΈ Π½Π°ΠΆΠ°Ρ‚ΠΈΠΈ ΠΊΠ½ΠΎΠΏΠΎΠΊ Π²Π½ΠΈΠ· ΠΈΠ»ΠΈ Π²Π²Π΅Ρ€Ρ… Π΄Π°Π½Π½ΠΎΠ³ΠΎ элСмСнта

Π‘Ρ‚Ρ€ΠΎΠΊΠΎΠ²ΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ any ΠΎΠ·Π½Π°Ρ‡Π°Π΅Ρ‚, Ρ‡Ρ‚ΠΎ Π½ΠΈΠΊΠ°ΠΊΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ шага Π½Π΅ Π·Π°Π΄Π°Π½ΠΎ ΠΈ допустимо любоС Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ (Π² ΠΏΡ€Π΅Π΄Π΅Π»Π°Ρ… Π΄Ρ€ΡƒΠ³ΠΈΡ… ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½ΠΈΠΉ, Ρ‚Π°ΠΊΠΈΡ… ΠΊΠ°ΠΊ min ΠΈ max ).

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: Когда Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅, Π²Π²Π΅Π΄Ρ‘Π½Π½ΠΎΠ΅ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΌ, Π½Π΅ ΠΏΠΎΠ΄Ρ…ΠΎΠ΄ΠΈΡ‚ ΠΏΠΎΠ΄ Π·Π°Π΄Π°Π½Π½ΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ шага, user agent ΠΌΠΎΠΆΠ΅Ρ‚ ΠΎΠΊΡ€ΡƒΠ³Π»ΠΈΡ‚ΡŒ Π΅Π³ΠΎ Π΄ΠΎ блиТайшСго допустимого значСния с ΠΏΡ€ΠΈΠΎΡ€ΠΈΡ‚Π΅Ρ‚ΠΎΠΌ Π² Π±ΠΎΠ»ΡŒΡˆΡƒΡŽ сторону Π² Ρ‚ΠΎΠΌ случаС, Ссли Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ находится Ρ€ΠΎΠ²Π½ΠΎ посСрСдинС шага.

Для ΠΏΠΎΠ»Π΅ΠΉ Π²Π²ΠΎΠ΄Π° date Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ step задаётся Π² днях; ΠΈ являСтся количСством миллисСкунд, Ρ€Π°Π²Π½ΠΎΠ΅ 86 400 000 ΡƒΠΌΠ½ΠΎΠΆΠΈΡ‚ΡŒ Π½Π° Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ step (ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌΠΎΠ΅ числовоС Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ хранится Π² миллисСкундах). Π‘Ρ‚Π°Π½Π΄Π°Ρ€Ρ‚Π½ΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ step Ρ€Π°Π²Π½ΠΎ 1, Ρ‡Ρ‚ΠΎ ΠΎΠ·Π½Π°Ρ‡Π°Π΅Ρ‚ 1 дСнь.

ИспользованиС ΠΏΠΎΠ»Π΅ΠΉ Π²Π²ΠΎΠ΄Π° c Ρ‚ΠΈΠΏΠΎΠΌ date

На ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ взгляд, элСмСнт выглядит Π·Π°ΠΌΠ°Π½Ρ‡ΠΈΠ²ΠΎ β€” ΠΎΠ½ прСдоставляСт Π»Ρ‘Π³ΠΊΠΈΠΉ графичСский интСрфСйс для Π²Ρ‹Π±ΠΎΡ€Π° Π΄Π°Ρ‚Ρ‹, Π½ΠΎΡ€ΠΌΠ°Π»ΠΈΠ·ΡƒΠ΅Ρ‚ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ Π΄Π°Ρ‚Ρ‹, отправляСмой Π½Π° сСрвСр нСзависимо ΠΎΡ‚ Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… настроСк ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ. Π’Π΅ΠΌ Π½Π΅ ΠΌΠ΅Π½Π΅Π΅, Π΅ΡΡ‚ΡŒ ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΡ‹ с Π² связи с ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½Π½ΠΎΠΉ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠΎΠΉ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€ΠΎΠ².

НадССмся, со Π²Ρ€Π΅ΠΌΠ΅Π½Π΅ΠΌ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π°ΠΌΠΈ станСт повсСмСстной, ΠΈ эта ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΠ° исчСзнСт.

Как ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ date?

Установка максимальной ΠΈ минимальной Π΄Π°Ρ‚Ρ‹

Π’ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π΅ выполнСния ΠΊΠΎΠ΄Π°, ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒ смоТСт Π²Ρ‹Π±Ρ€Π°Ρ‚ΡŒ любой дСнь апрСля 2017 Π³ΠΎΠ΄Π°, Π½ΠΎ Π½Π΅ смоТСт Π²Ρ‹Π±Ρ€Π°Ρ‚ΡŒ ΠΈ Π΄Π°ΠΆΠ΅ ΠΏΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Π΄Π½ΠΈ Π΄Ρ€ΡƒΠ³ΠΈΡ… мСсяцСв ΠΈ Π³ΠΎΠ΄ΠΎΠ², Π² Ρ‚ΠΎΠΌ числС Ρ‡Π΅Ρ€Π΅Π· Π²ΠΈΠ΄ΠΆΠ΅Ρ‚ date picker.

Controlling input size

Validation

By default, does not apply any validation to entered values. The UI implementations generally don’t let you enter anything that isn’t a date β€” which is helpful β€” but you can still leave the field empty or (in browsers where the input falls back to type text ) enter an invalid date (e.g. the 32nd of April).

If you use min and max to restrict the available dates (see Setting maximum and minimum dates), supporting browsers will display an error if you try to submit a date that is outside the set bounds. However, you’ll have to check the results to be sure the value is within these dates, since they’re only enforced if the date picker is fully supported on the user’s device.

In addition, you can use the required attribute to make filling in the date mandatory β€” again, an error will be displayed if you try to submit an empty date field. This, at least, should work in most browsers.

Let’s look at an example β€” here we’ve set minimum and maximum dates, and also made the field required:

If you try to submit the form with an incomplete date (or with a date outside the set bounds), the browser displays an error. Try playing with the example now:

Here’s a screenshot for those of you who aren’t using a supporting browser:

для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π€ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

Here’s the CSS used in the above example. Here we make use of the :valid and :invalid CSS properties to style the input based on whether or not the current value is valid. We had to put the icons on a next to the input, not on the input itself, because in Chrome the generated content is placed inside the form control, and can’t be styled or shown effectively.

Important: HTML form validation is not a substitute for scripts that ensure that the entered data is in the proper format. It’s far too easy for someone to make adjustments to the HTML that allow them to bypass the validation, or to remove it entirely. It’s also possible for someone to simply bypass your HTML entirely and submit the data directly to your server. If your server-side code fails to validate the data it receives, disaster could strike when improperly-formatted data is submitted (or data which is too large, is of the wrong type, and so forth).

Handling browser support

As mentioned above, the major problem with using date inputs at the time of writing is browser support. As an example, the date picker on Firefox for Android looks like this:

для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π€ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

Non-supporting browsers gracefully degrade to a text input, but this creates problems both in terms of consistency of user interface (the presented control will be different), and data handling.

One way around this is to put a pattern attribute on your date input. Even though the date input doesn’t use it, the text input fallback will. For example, try viewing the following example in a non-supporting browser:

The best way to deal with dates in forms in a cross-browser way at the moment is to get the user to enter the day, month, and year in separate controls ( elements being popular; see below for an implementation), or to use a JavaScript library such as jQuery date picker.

Examples

In this example we create two sets of UI elements for choosing dates: a native picker and a set of three elements for choosing dates in older browsers that don’t support the native input.

The HTML looks like so:

The months are hardcoded (as they are always the same), while the day and year values are dynamically generated depending on the currently selected month and year, and the current year (see the code comments below for detailed explanations of how these functions work.)

JavaScript

Note: Remember that some years have 53 weeks in them (see Weeks per year)! You’ll need to take this into consideration when developing production apps.

Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

Для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

Π­Ρ‚ΠΎ ΠΏΠΎΠ»Π΅, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ позволяСт Π²Ρ‹Π±Ρ€Π°Ρ‚ΡŒ Ρ†Π²Π΅Ρ‚.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

Атрибут value ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ для установки исходного Ρ†Π²Π΅Ρ‚Π°, Π΅Π³ΠΎ ΠΌΠΎΠΆΠ½ΠΎ Π½Π΅ ΡƒΠΊΠ°Π·Ρ‹Π²Π°Ρ‚ΡŒ.

ПолС Π²Π²ΠΎΠ΄Π° Π΄Π°Ρ‚Ρ‹

ПолС Ρ‚ΠΈΠΏΠ° date позволяСт ввСсти Π΄Π°Ρ‚Ρƒ с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ калСндаря.

МоТно Π·Π°Π΄Π°Ρ‚ΡŒ ниТнюю ΠΈ Π²Π΅Ρ€Ρ…Π½ΡŽΡŽ Π³Ρ€Π°Π½ΠΈΡ†Ρƒ Π΄ΠΈΠ°ΠΏΠ°Π·ΠΎΠ½Π° Π΄Π°Ρ‚ Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Π°ΠΌΠΈ min ΠΈ max.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

ПолС Π²Π²ΠΎΠ΄Π° адрСса элСктронной ΠΏΠΎΡ‡Ρ‚Ρ‹

Для Π²Π²ΠΎΠ΄Π° Π½Π΅ΡΠΊΠΎΠ»ΡŒΠΊΠΈΡ… адрСсов ΠΌΠΎΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ multiple, ΠΏΡ€ΠΈ этом для раздСлСния адрСсов ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ запятая (,)

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

Π€Π°ΠΉΠ» FILE

ΠŸΠΎΠ·Π²ΠΎΠ»ΡΠ΅Ρ‚ ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‚ΡŒ ΡΡ†Π΅Π½Π°Ρ€ΠΈΡŽ любой Ρ„Π°ΠΉΠ». ΠœΠ°ΠΊΡΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ Ρ€Π°Π·ΠΌΠ΅Ρ€ Ρ„Π°ΠΉΠ»Π° Π² Π±Π°ΠΉΡ‚Π°Ρ… задаСтся скрытым ΠΏΠΎΠ»Π΅ΠΌ max_file_size.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

Π‘Ρ†Π΅Π½Π°Ρ€ΠΈΠΉ получСния Ρ„Π°ΠΉΠ»Π° Π½Π° PHP:

Π‘Ρ€Π°ΡƒΠ·Π΅Ρ€ Chrome ΠΏΠΎΠ½ΠΈΠΌΠ°Π΅Ρ‚ Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Ρ‹ «webkitdirectory directory«, ΡƒΠΊΠ°Π·Π°Π½ΠΈΠ΅ ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Ρ… Ρƒ input позволяСт Π²Ρ‹Π±ΠΈΡ€Π°Ρ‚ΡŒ Ρ†Π΅Π»Ρ‹Π΅ ΠΏΠ°ΠΏΠΊΠΈ:

Π‘ΠΊΡ€Ρ‹Ρ‚ΠΎΠ΅ ΠΏΠΎΠ»Π΅ HIDDEN

Π­Ρ‚ΠΎ ΡΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹ΠΉ (скрытый) Ρ‚ΠΈΠΏ тСкстового поля. Если ΠΎΠ΄ΠΈΠ½ сцСнарий ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°Π΅Ρ‚ нСсколько Ρ€Π°Π·Π½Ρ‹Ρ… Ρ„ΠΎΡ€ΠΌ, Ρ‚ΠΎ Π² скрытом ΠΏΠΎΠ»Π΅ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ Ρ„ΠΎΡ€ΠΌΡ‹ ΠΌΠΎΠΆΠ½ΠΎ ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΏΠΎΠ·Π²ΠΎΠ»ΠΈΡ‚ ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΠΈΡ‚ΡŒ, с ΠΊΠ°ΠΊΠΎΠΉ Ρ„ΠΎΡ€ΠΌΠΎΠΉ Π²Ρ‹ ΠΈΠΌΠ΅Π΅Ρ‚Π΅ Π΄Π΅Π»ΠΎ.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

Π‘Ρ€Π°ΡƒΠ·Π΅Ρ€ Π½Π΅ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°Π΅Ρ‚ скрытоС ΠΏΠΎΠ»Π΅, хотя Π΅Π³ΠΎ ΠΌΠΎΠΆΠ½ΠΎ ΠΎΠ±Π½Π°Ρ€ΡƒΠΆΠΈΡ‚ΡŒ, Ссли пСрСвСсти Π±Ρ€ΠΎΡƒΠ·Π΅Ρ€ Π² Ρ€Π΅ΠΆΠΈΠΌ просмотра HTML-Ρ„Π°ΠΉΠ»Π° ΠΈ ΠΏΡ€ΠΎΠ°Π½Π°Π»ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ тСкст Web-страницы. Π‘ΠΊΡ€Ρ‹Ρ‚Ρ‹Π΅ поля ΠΏΠΎΠ»Π΅Π·Π½Ρ‹, Ссли Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ Ρ‚Ρ€Π΅Π±ΡƒΠ΅ΠΌΡƒΡŽ для сцСнария ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ, Π½ΠΎ ΠΏΡ€ΠΈ этом Π½Π΅ΠΆΠ΅Π»Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒ ΠΈΠΌΠ΅Π» Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ Π²Π½ΠΎΡΠΈΡ‚ΡŒ Π² Π½Π΅Π΅ измСнСния. Однако ΡƒΡ‡Ρ‚ΠΈΡ‚Π΅, Ρ‡Ρ‚ΠΎ ΡΠΎΠΎΠ±Ρ€Π°Π·ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒ ΠΌΠΎΠΆΠ΅Ρ‚ ΡΠΎΡ…Ρ€Π°Π½ΠΈΡ‚ΡŒ Π²Π°ΡˆΡƒ Ρ„ΠΎΡ€ΠΌΡƒ Π² Ρ„Π°ΠΉΠ»Π΅, ΠΎΡ‚Ρ€Π΅Π΄Π°ΠΊΡ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π΅Π³ΠΎ, Π° Π·Π°Ρ‚Π΅ΠΌ ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‚ΡŒ эту Ρ„ΠΎΡ€ΠΌΡƒ сСрвСру Π² ΠΈΠ·ΠΌΠ΅Π½Π΅Π½Π½ΠΎΠΌ Π²ΠΈΠ΄Π΅. ΠŸΠΎΡΡ‚ΠΎΠΌΡƒ Π½Π΅ стоит ΠΏΠΎΠ»Π°Π³Π°Ρ‚ΡŒΡΡ Π½Π° скрытыС поля с Ρ†Π΅Π»ΡŒΡŽ создания ΠΊΠ°ΠΊΠΎΠΉ-Π»ΠΈΠ±ΠΎ Π·Π°Ρ‰ΠΈΡ‚Ρ‹.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

Π‘Ρ†Π΅Π½Π°Ρ€ΠΈΠΉ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ с ΠΈΠΌΠ΅Π½Π΅ΠΌ FormVersion, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΉ Π±ΡƒΠ΄Π΅Ρ‚ присвоСно значСния 1.2. Π­Ρ‚Π° информация ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ для опрСдСлСния способа ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ ΠΎΡΡ‚Π°Π»ΡŒΠ½ΠΎΠΉ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠΈ, ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½ΠΎΠΉ ΠΎΡ‚ Ρ„ΠΎΡ€ΠΌΡ‹. Если ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ это Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅, Ρ‚ΠΎ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ° сцСнария ΠΌΠΎΠΆΠ΅Ρ‚ повСсти сСбя Π½Π΅ΠΎΠΆΠΈΠ΄Π°Π½Π½Ρ‹ΠΌ ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ.

ПолС Π²Π²ΠΎΠ΄Π° чисСл NUMBER

ПолС ΠΏΡ€Π΅Π΄Π½Π°Π·Π½Π°Ρ‡Π΅Π½ΠΎ для Π²Π²ΠΎΠ΄Π° чисСл. Дробная Ρ‡Π°ΡΡ‚ΡŒ ΠΏΡ€ΠΈ Π²Π²ΠΎΠ΄Π΅ ΠΌΠΎΠΆΠ΅Ρ‚ ΠΎΡ‚Π΄Π΅Π»ΡΡ‚ΡŒΡΡ ΠΊΠ°ΠΊ Ρ‚ΠΎΡ‡ΠΊΠΎΠΉ (2.5), Ρ‚Π°ΠΊ ΠΈ запятой (2,5). Если ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒ Π²Π²Π΅Π΄Π΅Ρ‚ Π±ΡƒΠΊΠ²Ρ‹, Ρ‚ΠΎ ΠΎΡ‚ΠΏΡ€Π°Π²ΠΈΡ‚ΡŒ Ρ„ΠΎΡ€ΠΌΡƒ Π½Π° сСрвСр Π½Π΅ удастся.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

МоТно Π·Π°Π΄Π°Ρ‚ΡŒ минимальноС, максимальноС Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ поля ΠΈ шаг измСнСния числа. Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ шага ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΊΠ°ΠΊ Ρ†Π΅Π»Ρ‹ΠΌ, Ρ‚Π°ΠΊ ΠΈ Π΄Ρ€ΠΎΠ±Π½Ρ‹ΠΌ, Π½ΠΎ Π΄ΠΎΠ»ΠΆΠ½ΠΎ Π±Ρ‹Ρ‚ΡŒ большС 0. Если Π²Π²Π΅Π΄Π΅Π½Π½ΠΎΠ΅ Π² ΠΏΠΎΠ»Π΅ число Π½Π΅ Π±ΡƒΠ΄Π΅Ρ‚ ΠΎΡ‚Π²Π΅Ρ‡Π°Ρ‚ΡŒ Π·Π°Π΄Π°Π½Π½Ρ‹ΠΌ ограничСниям, Ρ‚ΠΎ ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠ° Π½Π° сСрвСр Π½Π΅ ΠΏΡ€ΠΎΠΈΠ·ΠΎΠΉΠ΄Π΅Ρ‚.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

Для задания любого шага ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ step=»any».

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

ПолС number отобраТаСтся ΠΏΠΎ-Ρ€Π°Π·Π½ΠΎΠΌΡƒ: Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Ρ‹ ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°ΡŽΡ‚ стрСлочки всСгда, Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ – Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΏΡ€ΠΈ Π½Π°Π²Π΅Π΄Π΅Π½ΠΈΠΈ ΠΈΠ»ΠΈ ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠΈ ΠΏΠΎΠ»Π΅ΠΌ фокуса.

Если Π½ΡƒΠΆΠ½ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ стрСлочки Π² ΠΏΠΎΠ»Π΅ number Π±Ρ‹Π»ΠΈ всСгда, Π·Π°Π΄Π°ΠΉΡ‚Π΅ ΡΡ‚ΠΈΠ»ΡŒ:

Если Π½ΡƒΠΆΠ½ΠΎ ΡƒΠ±Ρ€Π°Ρ‚ΡŒ стрСлочки Π² ΠΏΠΎΠ»Π΅ number, Π·Π°Π΄Π°ΠΉΡ‚Π΅ ΡΡ‚ΠΈΠ»ΡŒ:

ПолС Π²Π²ΠΎΠ΄Π° пароля PASSWORD

ПолС Π²Π²ΠΎΠ΄Π° пароля ΠΎΡ‡Π΅Π½ΡŒ ΠΏΠΎΡ…ΠΎΠΆΠ΅ Π½Π° простоС тСкстовоС ΠΏΠΎΠ»Π΅. ΠžΡ‚Π»ΠΈΡ‡Π°Π΅Ρ‚ΡΡ ΠΎΠ½ΠΎ Ρ‚Π΅ΠΌ, Ρ‡Ρ‚ΠΎ вмСсто Π²Π²ΠΎΠ΄ΠΈΠΌΡ‹Ρ… символов Π² Π½Π΅ΠΌ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°ΡŽΡ‚ΡΡ Ρ‚ΠΎΡ‡ΠΊΠΈ. Вакая Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ ΠΎΡ‡Π΅Π½ΡŒ Π²Π°ΠΆΠ½Π°, ΠΊΠΎΠ³Π΄Π° Π½ΡƒΠΆΠ½ΠΎ ввСсти ΡΠ΅ΠΊΡ€Π΅Ρ‚Π½ΡƒΡŽ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ, Ρ‚ΠΈΠΏΠ° пароля, ΠΊΠΎΡ‚ΠΎΡ€ΡƒΡŽ Π½Π΅ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π²ΠΈΠ΄Π΅Ρ‚ΡŒ Π΄Ρ€ΡƒΠ³ΠΈΠ΅.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

ΠŸΠ΅Ρ€Π΅ΠΊΠ»ΡŽΡ‡Π°Ρ‚Π΅Π»ΡŒ RADIO

ΠŸΠ΅Ρ€Π΅ΠΊΠ»ΡŽΡ‡Π°Ρ‚Π΅Π»ΡŒ Π½Π°ΠΏΠΎΠΌΠΈΠ½Π°Π΅Ρ‚ Ρ„Π»Π°ΠΆΠΎΠΊ, ΠΏΠΎΡΠΊΠΎΠ»ΡŒΠΊΡƒ ΠΎΠ½ Ρ‚ΠΎΠΆΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚ Π½Π°Ρ…ΠΎΠ΄ΠΈΡ‚ΡŒΡΡ Π²ΠΎ Π²ΠΊΠ»ΡŽΡ‡Π΅Π½Π½ΠΎΠΌ ΠΈΠ»ΠΈ Π²Ρ‹ΠΊΠ»ΡŽΡ‡Π΅Π½Π½ΠΎΠΌ состоянии.

По смыслу всСгда прСдполагаСтся, Ρ‡Ρ‚ΠΎ Π² Ρ„ΠΎΡ€ΠΌΠ΅ имССтся нСсколько ΠΏΠ΅Ρ€Π΅ΠΊΠ»ΡŽΡ‡Π°Ρ‚Π΅Π»Π΅ΠΉ с ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΌ Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠΌ name. Π£ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ ΠΈΠ· Π½ΠΈΡ… своС Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Π° value. Π“Ρ€ΡƒΠΏΠΏΠ° ΠΏΠ΅Ρ€Π΅ΠΊΠ»ΡŽΡ‡Π°Ρ‚Π΅Π»Π΅ΠΉ с ΠΎΠ΄Π½ΠΈΠΌ ΠΈ Ρ‚Π΅ΠΌ ΠΆΠ΅ ΠΈΠΌΠ΅Π½Π΅ΠΌ Π² Ρ„ΠΎΡ€ΠΌΠ΅ Π²Π΅Π΄Π΅Ρ‚ сСбя Ρ‚Π°ΠΊΠΈΠΌ ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ, Ρ‡Ρ‚ΠΎ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΎΠ΄ΠΈΠ½ ΠΈΠ· Π½ΠΈΡ… ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ Π²ΠΊΠ»ΡŽΡ‡Π΅Π½Π½Ρ‹ΠΌ. ΠŸΡ€ΠΈ ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‡Π΅ Π΄Π°Π½Π½Ρ‹Ρ… пСрСдаСтся Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π²Ρ‹Π±Ρ€Π°Π½Π½ΠΎΠ³ΠΎ ΠΏΠ΅Ρ€Π΅ΠΊΠ»ΡŽΡ‡Π°Ρ‚Π΅Π»Ρ.

Один ΠΏΠ΅Ρ€Π΅ΠΊΠ»ΡŽΡ‡Π°Ρ‚Π΅Π»ΡŒ ΠΈΠ· Π³Ρ€ΡƒΠΏΠΏΡ‹ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΈΠ·Π½Π°Ρ‡Π°Π»ΡŒΠ½ΠΎ Π²Ρ‹Π±Ρ€Π°Π½ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Π° checked.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

ΠŸΠΎΠ»Π·ΡƒΠ½ΠΎΠΊ RANGE

ПолС ΠΏΡ€Π΅Π΄Π½Π°Π·Π½Π°Ρ‡Π΅Π½ΠΎ для Π²Π²ΠΎΠ΄Π° числа Π² ΡƒΠΊΠ°Π·Π°Π½Π½ΠΎΠΌ Π΄ΠΈΠ°ΠΏΠ°Π·ΠΎΠ½Π΅.

МоТно Π·Π°Π΄Π°Ρ‚ΡŒ минимальноС Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ (ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ 0), максимальноС Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ (ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ 100), шаг измСнСния числа (ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ 1) ΠΈ Ρ‚Π΅ΠΊΡƒΡ‰Π΅Π΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ (ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ срСднСС арифмСтичСскоС минимального ΠΈ максимального Π·Π½Π°Ρ‡Π΅Π½ΠΈΠΉ).

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

ΠŸΠΎΠ»Π·ΡƒΠ½ΠΎΠΊ сам ΠΏΠΎ сСбС Π½Π΅ Π΄Π°Ρ‘Ρ‚ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŽ прСдставлСниС, ΠΊΠ°ΠΊΠΎΠ΅ ΠΆΠ΅ число ΠΎΠ½ Π²Ρ‹Π±Ρ€Π°Π». ΠŸΠΎΡΡ‚ΠΎΠΌΡƒ здСсь Π±Π΅Π· JavaScript Π½Π΅ ΠΎΠ±ΠΎΠΉΡ‚ΠΈΡΡŒ.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

ПолС range отобраТаСтся Ρ€Π°Π·Π½Ρ‹ΠΌΠΈ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π°ΠΌΠΈ ΠΏΠΎ-Ρ€Π°Π·Π½ΠΎΠΌΡƒ.

Если Ρ…ΠΎΡ‚ΠΈΡ‚Π΅ своё ΠΎΡ„ΠΎΡ€ΠΌΠ»Π΅Π½ΠΈΠ΅, Π·Π°Π΄Π°ΠΉΡ‚Π΅ стили для ΠΏΠΎΠ»Π·ΡƒΠ½ΠΊΠ°:

Но ΠΏΠΎΠ±Π΅Π΄ΠΈΡ‚ΡŒ Π΄ΠΎ ΠΊΠΎΠ½Ρ†Π° стили IE11 Π½Π΅ удастся!

Кнопка RESET

Π­Ρ‚ΠΎ ΠΊΠ½ΠΎΠΏΠΊΠ° очистки Ρ„ΠΎΡ€ΠΌΡ‹. ΠŸΡ€ΠΈ Π΅Π΅ Π½Π°ΠΆΠ°Ρ‚ΠΈΠΈ всСм ΠΈΠ·ΠΌΠ΅Π½Π΅Π½Π½Ρ‹ΠΌ элСмСнтам возвращаСтся Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ. ΠŸΡ€ΠΈΠΌΠ΅Π½ΡΠ΅Ρ‚ΡΡ ΠΎΠ½Π° достаточно Ρ€Π΅Π΄ΠΊΠΎ. Однако Π² Π½Π΅ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Ρ… случаях ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ вСсьма ΠΏΠΎΠ»Π΅Π·Π½Π°.

Π‘ΠΎΠ²Π΅Ρ‚: остороТно ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅ΡΡŒ ΠΊ Π²Ρ‹Π±ΠΎΡ€Ρƒ надписи Π½Π° ΠΊΠ½ΠΎΠΏΠΊΠ΅ RESET. Π’ΠΏΠΎΠ»Π½Π΅ наглядным (ΠΈ, Π³Π»Π°Π²Π½ΠΎΠ΅, ΠΈΠ½Ρ‚ΡƒΠΈΡ‚ΠΈΠ²Π½ΠΎ понятным Π΄Π°ΠΆΠ΅ Ρ‡Π°ΠΉΠ½ΠΈΠΊΡƒ ΠΈΠ· Ρ‡Π°ΠΉΠ½ΠΈΠΊΠΎΠ²) Π±ΡƒΠ΄Π΅Ρ‚ Ρ‡Ρ‚ΠΎ-Π½ΠΈΠ±ΡƒΠ΄ΡŒ Π²Ρ€ΠΎΠ΄Π΅ Β«ΠžΡ‡ΠΈΡΡ‚ΠΈΡ‚ΡŒΒ», Β«ΠΠ°Ρ‡Π°Ρ‚ΡŒ сначала», Β«Π£Π΄Π°Π»ΠΈΡ‚ΡŒ Π²Π²ΠΎΠ΄Β» ΠΈ Ρ‚.ΠΏ. Π’ ΠΎΠ±Ρ‰Π΅ΠΌ, Π½Π°Π΄ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Ρƒ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ Π½Π΅ Π·Π°ΠΊΡ€Π°Π»ΠΎΡΡŒ ΠΈ Ρ‚Π΅Π½ΠΈ сомнСния ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ прСдназначСния этой клавиши.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

Кнопка SUBMIT

Π­Ρ‚Π° ΠΊΠ½ΠΎΠΏΠΊΠ° ΠΏΡ€Π΅Π΄Π½Π°Π·Π½Π°Ρ‡Π΅Π½Π° для ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‡ΠΈ Ρ„ΠΎΡ€ΠΌΡ‹. Π’ Π±ΠΎΠ»ΡŒΡˆΠΈΠ½ΡΡ‚Π²Π΅ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€ΠΎΠ² внСшнС ΠΏΠΎΡ‡Ρ‚ΠΈ Π½Π΅ ΠΎΡ‚Π»ΠΈΡ‡ΠΈΠΌΠ° ΠΎΡ‚ ΠΊΠ½ΠΎΠΏΠΊΠΈ BUTTON. Π‘Π°ΠΌΠ° ΠΎΠ½Π° Π½Π΅ пСрСдаСтся, Π° слуТит Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для управлСния.

Атрибут onclick для ΠΊΠ½ΠΎΠΏΠΊΠΈ SUBMIT практичСски Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ, Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ Π»ΡƒΡ‡ΡˆΠ΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊ событий onsubmit, Π·Π°Π΄Π°Π½Π½Ρ‹ΠΉ Π² Ρ‚Π΅Π³Π΅

Атрибут value Π΄Π°Π΅Ρ‚ ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½Ρ‹Π΅ прСимущСства ΠΏΡ€ΠΈ использовании Π±ΠΎΠ»Π΅Π΅ ΠΎΠ΄Π½ΠΎΠΉ ΠΊΠ½ΠΎΠΏΠΊΠΈ ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‡ΠΈ Π΄Π°Π½Π½Ρ‹Ρ…. Π’ этом случаС Π½Π° основании значСния ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½ΠΎΠΉ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ сцСнарий смоТСт ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΠΈΡ‚ΡŒ, ΠΊΠ°ΠΊ ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°Ρ‚ΡŒ ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½ΡƒΡŽ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ Π΄Π°Π»Π΅Π΅.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

Атрибут formnovalidate ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΏΡ€ΠΈΠΌΠ΅Π½Π΅Π½, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΡ€Π΅Π΄ΠΎΡ‚Π²Ρ€Π°Ρ‚ΠΈΡ‚ΡŒ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΡƒ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠΉ Ρ„ΠΎΡ€ΠΌΡ‹.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

ПолС ввода TEXT

ВСкстовоС ΠΏΠΎΠ»Π΅ Π²Π²ΠΎΠ΄Π° ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ Π² Ρ„ΠΎΡ€ΠΌΠ°Ρ… Π½Π°ΠΈΠ±ΠΎΠ»Π΅Π΅ часто. Π‘ΠΎΠ»Π΅Π΅ Ρ‚ΠΎΠ³ΠΎ, Π΅Π³ΠΎ ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠΎ ΠΏΡ€Π°Π²Ρƒ ΡΡ‡ΠΈΡ‚Π°Ρ‚ΡŒ основным ΠΈ главнСйшим элСмСнтом Ρ„ΠΎΡ€ΠΌ. Π­Ρ‚ΠΎΡ‚ Ρ‚ΠΈΠΏ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ Ρ‚Π΅Π³ΠΎΠΌ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ, Π΅Π³ΠΎ ΠΌΠΎΠΆΠ½ΠΎ Π½Π΅ ΡƒΠΊΠ°Π·Ρ‹Π²Π°Ρ‚ΡŒ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ вывСсти тСкстовоС ΠΏΠΎΠ»Π΅. Однако, Ссли Π²ΠΎΠ·Π½ΠΈΠΊΠ½Π΅Ρ‚ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎΡΡ‚ΡŒ Π·Π°Π΄Π°Ρ‚ΡŒ ΡΡ‚ΠΈΠ»ΡŒ для сСлСктора input[type=»text»], Ρ‚ΠΎ Ρ‚ΠΎΠ³Π΄Π° Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ type=»text» ΠΏΡ€ΠΎΠΏΡƒΡΠΊΠ°Ρ‚ΡŒ нСльзя.
Имя поля, Π·Π°Π΄Π°Π²Π°Π΅ΠΌΠΎΠ΅ Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ΠΎΠΌ name, всСгда ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ, Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ Π±Π°Π·ΠΈΡ€ΡƒΡΡΡŒ ΠΈΠΌΠ΅Π½Π½ΠΎ Π½Π° этом ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Π΅, Π±Ρ€Π°ΡƒΠ·Π΅Ρ€ ΠΏΠ΅Ρ€Π΅Π΄Π°Π΅Ρ‚ ΡΡ†Π΅Π½Π°Ρ€ΠΈΡŽ ΠΏΠ°Ρ€Ρƒ имя=Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€

ВСкст «Иванов» помСщаСтся Π² созданноС ΠΏΠΎΠ»Π΅ Π² качСствС Π½Π°Ρ‡Π°Π»ΡŒΠ½ΠΎΠ³ΠΎ значСния. Если ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒ Π½Π΅ внСсСт ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ ΠΈΠ»ΠΈ Π½Π°ΠΆΠΌΠ΅Ρ‚ ΠΊΠ½ΠΎΠΏΠΊΡƒ RESET, Ρ‚ΠΎ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ Иванов Π±ΡƒΠ΄Π΅Ρ‚ ΠΎΡ‚ΠΏΡ€Π°Π²Π»Π΅Π½ΠΎ ΡΡ†Π΅Π½Π°Ρ€ΠΈΡŽ Π² качСствС Ρ„Π°ΠΌΠΈΠ»ΠΈΠΈ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ.

Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

Для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

элСмСнт Ρ‚ΠΈΠΏΠ° datetime-local создаёт поля Π²Π²ΠΎΠ΄Π°, ΠΏΠΎΠ·Π²ΠΎΠ»ΡΡŽΡ‰ΠΈΠ΅ Π»Π΅Π³ΠΊΠΎ ввСсти Π΄Π°Ρ‚Ρƒ ΠΈ врСмя β€” Π³ΠΎΠ΄, мСсяц, дСнь, часы ΠΈ ΠΌΠΈΠ½ΡƒΡ‚Ρ‹.

Для Ρ‚Π΅Ρ… ΠΈΠ· вас, ΠΊΡ‚ΠΎ Π½Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°ΡŽΡ‰ΠΈΠΉ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€, Chrome/Opera datetime-local control выглядит ΠΊΠ°ΠΊ ΡΠΊΡ€ΠΈΠ½ΡˆΠΎΡ‚ Π½ΠΈΠΆΠ΅. НаТатиС Π½Π° стрСлку Π²Π½ΠΈΠ· с ΠΏΡ€Π°Π²ΠΎΠΉ стороны ΠΏΡ€ΠΈΠ²ΠΎΠ΄ΠΈΡ‚ ΠΊ Π²Ρ‹Π±ΠΎΡ€Ρƒ Π΄Π°Ρ‚Ρ‹, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π²Ρ‹ ΠΌΠΎΠ³Π»ΠΈ Π²Ρ‹Π±Ρ€Π°Ρ‚ΡŒ Π΄Π°Ρ‚Ρƒ; Π²Ρ‹ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ввСсти врСмя Π²Ρ€ΡƒΡ‡Π½ΡƒΡŽ.

для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π€ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π€ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π€ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅

DOMString прСдставлСниС значСния Π΄Π°Ρ‚Ρ‹, Π²Π²Π΅Π΄Ρ‘Π½Π½ΠΎΠΉ Π²ΠΎ Π²Ρ…ΠΎΠ΄Π½Ρ‹Π΅ Π΄Π°Π½Π½Ρ‹Π΅. Π’Ρ‹ ΠΌΠΎΠΆΠ΅Ρ‚Π΅ ΡƒΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚ΡŒ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ для Π²Π²ΠΎΠ΄Π°, Π²ΠΊΠ»ΡŽΡ‡Π°Ρ Π΄Π°Ρ‚Ρƒ Π²Π½ΡƒΡ‚Ρ€ΠΈ value Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Π°, ΠΊΠ°ΠΊ:

Π’Ρ‹ Ρ‚Π°ΠΊΠΆΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚Π΅ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ ΠΈ ΡƒΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚ΡŒ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ Π΄Π°Ρ‚Ρ‹ Π² JavaScript, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡ HTMLInputElement.value свойство, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€:

ИспользованиС Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… Π²Ρ…ΠΎΠ΄Π½Ρ‹Ρ… Π΄Π°Π½Π½Ρ‹Ρ… datetime

Π’Π²ΠΎΠ΄ Π΄Π°Ρ‚Ρ‹ ΠΈ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ выглядит ΡƒΠ΄ΠΎΠ±Π½ΠΎ Π½Π° ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ взгляд β€” ΠΎΠ½ обСспСчиваСт простой ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠΉ интСрфСйс для Π²Ρ‹Π±ΠΎΡ€Π° Π΄Π°Ρ‚Ρ‹ ΠΈ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ, ΠΈ ΠΎΠ½ΠΈ Π½ΠΎΡ€ΠΌΠ°Π»ΠΈΠ·ΡƒΡŽΡ‚ Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ Π΄Π°Π½Π½Ρ‹Ρ…, отправляСмых Π½Π° сСрвСр, нСзависимо ΠΎΡ‚ Π»ΠΎΠΊΠ°Π»ΠΈ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ. Π’Π΅ΠΌ Π½Π΅ ΠΌΠ΅Π½Π΅Π΅, Π΅ΡΡ‚ΡŒ ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΡ‹ с ΠΈΠ·-Π·Π° ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½Π½ΠΎΠΉ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠΈ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π°.

Π‘Π°Π·ΠΎΠ²ΠΎΠ΅ использованиС Π»ΠΎΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΏΠΎΠ»Π΅ΠΉ Π²Π²ΠΎΠ΄Π° datetime

Π‘Π°ΠΌΠΎΠ΅ простои использованиС Π²ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ ΠΊΠΎΠΌΠ±ΠΈΠ½Π°Ρ†ΠΈΡŽ Π±Π°Π·ΠΎΠ²ΠΎΠ³ΠΎ ΠΈ элСмСнта, ΠΊΠ°ΠΊ Π² ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π΅ Π½ΠΈΠΆΠ΅:

Установка максимума ΠΈ ΠΌΠΈΠ½ΠΈΠΌΡƒΠΌΠ° Π΄Π°Ρ‚Ρ‹ ΠΈ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ

Π’Ρ‹ ΠΌΠΎΠΆΠ΅Ρ‚Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ min ΠΈ max Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Ρ‹ Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡ΠΈΡ‚ΡŒ Π΄Π°Ρ‚Ρƒ/врСмя, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚ Π²Ρ‹Π±Ρ€Π°Ρ‚ΡŒ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒ. Π’ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π΅ Π½ΠΈΠΆΠ΅ ΠΌΡ‹ устанавливаСт ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹Π΅ Π΄Π°Ρ‚Ρƒ ΠΈ врСмя Π² 2017-06-01T08:30 ΠΈ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹Π΅ Π² 2017-06-30T16:30 :

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: БущСствуСт Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ step Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚ для Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΡƒΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚ΡŒ количСство Π΄Π½Π΅ΠΉ, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π±ΡƒΠ΄ΡƒΡ‚ ΠΏΡ€ΠΎΠΏΡƒΡ‰Π΅Π½Ρ‹ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ Ρ€Π°Π·, ΠΊΠΎΠ³Π΄Π° Π΄Π°Ρ‚Π° увСличиваСтся (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, Ссли Π²Ρ‹ Ρ…ΠΎΡ‚ΠΈΡ‚Π΅ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ доступными для Π²Ρ‹Π±ΠΎΡ€Π° Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Π‘ΡƒΠ±Π±ΠΎΡ‚Ρ‹). Однако, Π½Π° ΠΌΠΎΠΌΠ΅Π½Ρ‚ написаниС этой ΡΡ‚Π°Ρ‚ΡŒΠΈ это Π½Π΅Ρ‚ эффСктивной Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ этой Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ.

Controlling input size

Setting timezones

One thing the datetime-local input type doesn’t provide is a way to set the timezone/locale of the datetime. This was available in the datetime input type, but this type is now obsolete, having been removed from the spec. The main reasons why this was removed are a lack of implementation in browsers, and concerns over the user interface/experience. It is easier to just have a control (or controls) for setting the date/time and then deal with the locale in a separate control.

For example, if you are creating a system where the user is likely to already be logged in, with their locale already set, you could provide the timezone in a hidden input type. For example:

On the other hand, if you were required to allow the user to enter a timezone along with a datetime entry, you could provide a means of inputting a timezone, such as a element:

In either case, the timedate and timezone values would be submitted to the server as separate data points, and then you’d need to store them appropriately in the database on the server-side.

Note: The above code snippet is taken from All world timezones in an HTML select element.

Validation

By default, does not apply any validation to entered values. The UI implementations generally don’t let you enter anything that isn’t a datetime β€” which is helpful β€” but you can still fill in no value and submit, or enter an invalid datetime (e.g. the 32th of April).

You can use min and max to restrict the available dates (see anch(«Setting maximum and minimum dates»)), and in addition use the required attribute to make filling in the date mandatory. As a result, supporting browsers will display an error if you try to submit a date that is outside the set bounds, or an empty date field.

Let’s look at an example β€” here we’ve set minimum and maximum datetimes, and also made the field required:

If you try to submit the form with an incomplete date (or with a date outside the set bounds), the browser displays an error. Try playing with the example now:

Here’s’a screenshot for those of you who aren’t using a supporting browser:

для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π€ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

Here’s the CSS used in the above example. Here we make use of the :valid and :invalid CSS properties to style the input based on whether or not the current value is valid. We had to put the icons on a next to the input, not on the input itself, because in Chrome the generated content is placed inside the form control, and can’t be styled or shown effectively.

Important: HTML form validation is not a substitute for scripts that ensure that the entered data is in the proper format. It’s far too easy for someone to make adjustments to the HTML that allow them to bypass the validation, or to remove it entirely. It’s also possible for someone to simply bypass your HTML entirely and submit the data directly to your server. If your server-side code fails to validate the data it receives, disaster could strike when improperly-formatted data is submitted (or data which is too large, is of the wrong type, and so forth).

Handling browser support

As mentioned above, the major problem with using date inputs at the time of writing is browser support β€” only Chrome/Opera and Edge support it on desktop, and most modern browsers on mobile. As an example, the datetime-local picker on Firefox for Android looks like this:

для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π‘ΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° ΠΏΡ€ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date. Π€ΠΎΡ‚ΠΎ для ΠΊΠ°ΠΊΠΈΡ… Ρ†Π΅Π»Π΅ΠΉ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ input type date

Non-supporting browsers gracefully degrade to a text input, but this creates problems both in terms of consistency of user interface (the presented control will be different), and data handling.

One way around this is to put a pattern attribute on your datetime-local input. Even though the datetime-local input doesn’t use it, the text input fallback will. For example, try viewing the following demo in a non-supporting browser:

And what user is going to understand the pattern they need to enter the time and date in?

We still have a problem.

The best way to deal with dates in forms in a cross-browser way at the moment is to get the user to enter the day, month, year, and time in separate controls ( elements being popular β€” see below for an implementation), or use JavaScript libraries such as jQuery date picker, and the jQuery timepicker plugin.

Examples

In this example we create two sets of UI elements for choosing datetimes β€” a native picker, and a set of five elements for choosing dates and times in older browsers that don’t support the native input.

The HTML looks like so:

The months are hardcoded (as they are always the same), while the day and year values are dynamically generated depending on the currently selected month and year, and the current year respectively (see the code comments below for detailed explanations of how these functions work.) We also decided to dynamically generate the hours and months, as there are so many of them!

Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ

Π’Π°Ρˆ адрСс email Π½Π΅ Π±ΡƒΠ΄Π΅Ρ‚ ΠΎΠΏΡƒΠ±Π»ΠΈΠΊΠΎΠ²Π°Π½. ΠžΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ поля ΠΏΠΎΠΌΠ΅Ρ‡Π΅Π½Ρ‹ *