关注html5输入的月份或年份[type =" date"] [英] focus month or year of html5 input[type="date"]

查看:821
本文介绍了关注html5输入的月份或年份[type =" date"]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提供了一个小提示,显示当您将焦点应用于元素时会发生什么,它将焦点设置为输入的日期部分,但我找不到有关DOM如何呈现和识别每个部分的任何文档。日期。

I included a fiddle showing what happens when you apply focus to the element, it sets the focus to the 'day' part of the input, but I can't find any documentation on how the DOM renders and identifies each portion of the date.

如何以编程方式聚焦输入的月份/年份[type =date] 元素,是否有关于如何在DOM中呈现此类元素的任何文档?

How can I programmatically focus the month/year portions of an input[type="date"] element, and is there any documentation on how this type of element gets rendered in the DOM?

https://jsfiddle.net/uytdhqax/

<input id="dob" type="date" />



document.getElementById('dob').focus()


推荐答案

这不是在我所知的情况下,在输入[type = date] 元素的任何当前实现中都是可能的。此外,不同的浏览器以不同的方式实现此元素,因此没有独立的实现文档。

This isn't possible in any current implementation of the input[type=date] element as far as I'm aware. Furthermore, different browsers implement this element in different ways, so there is no standalone implementation documentation.

人们不得不问为什么你想模仿这种行为。仅更改年份值不会为元素赋值,除非已设置日期和月份。至少在Chrome中,如果你有输入[type = date] 元素,你将会看到一个包含占位符文本的元素 dd / mm / YYYY 。如果您手动选择 yyyy 部分并将其更改为 2015 ,例如,输入的文本现在将显示为 dd / mm / 2015 ,但其将为 (一个空字符串)。除非您手动编辑日期和月份部分,否则强制关注年份将不会实现除用户混淆之外的其他任何事情。

One has to ask why you'd want to imitate this behaviour though. Changing the year value alone will not give the element a value unless the day and month have also been set. In Chrome, at least, if you have an input[type=date] element you'll be shown an element containing placeholder text dd/mm/yyyy. If you select the yyyy part manually and change this to 2015, for example, the input's text will now read dd/mm/2015, but its value will be "" (an empty string). Unless you're manually editing the day and month parts, forcing focus onto the year will not achieve anything other than confusion to users.

这篇关于关注html5输入的月份或年份[type =&quot; date&quot;]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆