Html 谷歌浏览器输入类型=“日期”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7243381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:21:33  来源:igfitidea点击:

Google Chrome input type="date"

htmlgoogle-chrome

提问by Random_Person

I have almost no knowledge of web programming, but I have been tasked to solve something on my company's website. Apparently, I have an issue with browsers using HTML5 on a legacy site using type="date" and I need to find a way around it.

我几乎没有网络编程的知识,但我的任务是解决我公司网站上的问题。显然,我在使用 type="date" 的旧网站上使用 HTML5 的浏览器存在问题,我需要找到解决方法。

My site has a lot of date fields that the user must input like such:

我的网站有很多日期字段,用户必须像这样输入:

 <input type="date" name="DateStart" size="15" value="8/30/2011">

In every browser we currently use except Chrome, this works just fine. Chrome is the only browser that supplies rolling buttons to scroll through the date. What I see on the back end of this is an attempt to do this:

在我们目前使用的除 Chrome 之外的所有浏览器中,这都能正常工作。Chrome 是唯一提供滚动按钮来滚动日期的浏览器。我在后端看到的是尝试这样做:

FormatDateTime(DateStart, 2)

I get an invalid date error which means that we cannot use Chrome to fill out this form. Is there a way around this problem?

我收到无效日期错误,这意味着我们无法使用 Chrome 填写此表单。有没有办法解决这个问题?

采纳答案by feeela

Chrome does not have issues with date-inputs, you are using the wrong date-format, sir. Chrome isn't the only browser until today which has support for the new HTML5 inputs. Opera for example displays a dropdown with a calendar on inputs with type="date".

Chrome 没有日期输入问题,先生,您使用了错误的日期格式。直到今天,Chrome 还不是唯一支持新 HTML5 输入的浏览器。例如,Opera 在输入上显示带有日历的下拉列表type="date"

Also the size-attribute does not exist on HTML5-date-inputs.

HTML5-date-inputs 上也不存在 size-attribute。

回答by Tom Christie

Actually chrome's support for 'date' isbroken. (See here). At least for the moment.

实际上,chrome 对“日期”的支持已被破坏。(见这里)。至少目前是这样。

The use of 'date' in the HTML is absolutely fine - browser's which do not know of or support an input type are supposed to fallback to type='text'.

在 HTML 中使用“日期”绝对没问题 - 不知道或不支持输入类型的浏览器应该回退到 type='text'。

Currently chrome partially supports date, in a way that is essentially broken (it adds a couple of up-down buttons, but no datepicker.)

目前 chrome 部分支持日期,但本质上已被破坏(它添加了几个上下按钮,但没有日期选择器。)

Of course you do need to bear in mind that if you areusing type='date', and if the browser supports it, then you'll want to disable whatever datepicker support you'd otherwise be using.

当然,你记住做需要承担,如果你正在使用类型=“日期”,如果浏览器支持的话,那么你会希望禁用否则你可以使用任何支持日期选择器。

UPDATE (6 Feb 2012):

更新(2012 年 2 月 6 日):

It looks to me like this is now fixed. Chrome no longer claims to support input type='date', and does not provide the partially complete implementation.

在我看来,这个问题现在已经解决了。Chrome 不再声称支持 input type='date',并且不提供部分完整的实现。

UPDATE (17 Aug 2012):

更新(2012 年 8 月 17 日):

Chrome doesnow have input type="date" support, and it's more functional this time.

Chrome浏览器确实现在有输入型=“日期”的支持,它的功能更强大这段时间。

回答by THBBFT

The value field for the input type = input needs to be in the format yyyy-MM-dd. Check the W3 standards on this.

input type = input 的值字段需要采用 yyyy-MM-dd 格式。 检查 W3 标准。

This means you must do something like DateTime.Now.ToString("yyyy-MM-dd"). in your code, I would suggest a custom HtmlHelper.

这意味着您必须执行类似 DateTime.Now.ToString("yyyy-MM-dd") 的操作。在您的代码中,我建议使用自定义 HtmlHelper。

The format of the date in the browser is completely dependent on your system settings.

浏览器中日期的格式完全取决于您的系统设置。

回答by Mizhar Raja

Use this date format : date("Y-m-d");

使用此日期格式: date("Y-m-d");