处理特定的浏览器支持HTML INPUT TYPE =&QUOT的;日期和QUOT; [英] Handling browser-specific support of HTML input type="date"

查看:285
本文介绍了处理特定的浏览器支持HTML INPUT TYPE =&QUOT的;日期和QUOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道的HTML 5 输入标签,用使用时,键入=日期,需要喂一个RFC 3339完整的日期描述这里。的问题很多这里,如<一个href=\"http://stackoverflow.com/questions/3496241/specifying-the-value-output-of-of-an-html5-input-type-date\">this 之一,提到这一点。

I am aware that the HTML 5 input tag, when used with type="date", needs to be fed an RFC 3339 full date as described here. Lots of questions here, such as this one, mention this.

不过,对于日期类型的输入标签浏览器支持变化了很多。例如,Safari浏览器在iOS 7采用了漂亮的日期选择器上,您可以上下翻页分别选择日,月,年。 Internet Explorer的10,而另一方面,不处理任何特殊方式日期类型的输入标签,把它们当作纯文本输入的标签。

However, browser support for the date type input tag varies a lot. For example, Safari on iOS 7 uses a nice date picker on which you can flip up and down to select day, month and year separately. Internet Explorer 10, on the other hand, does not handle date type input tags in any special way, treating them as plain text input tags.

当我们把这两个事实一起,我们发现如下。如果我喂我的网页格式正确的RFC 3339完整的日期上的日期类型的输入标签,符合市场预期,这显示它有它的特殊支持的浏览器,如Safari很好地在iOS 7.但是,输入标签显示了在浏览器不处理它的任何特殊的方式,如Internet Explorer 10的丑和用户不友好YYYY-MM-DD日期我不能显示YYYY-MM-DD日期以我的用户,所以我想我宁愿养活我输入标签用户友好的日期格式,如DD / MMM / YYYY(这是我们用在这里的格式)。但后来,这个工程上处理它为简单的文本,如Internet Explorer浏览器的确定;在Safari在iOS 7,这需要一个适当的RFC 3339完整的日期,日期类型的输入标签显示为空白。

When we put these two facts together, we find the following. If I feed the date type input tag on my page a properly-formatted RFC 3339 full date, as expected, it displays it nicely in browsers that have special support for it, such as Safari on iOS 7. However, the input tag shows an ugly and user-unfriendly yyyy-mm-dd date on browsers that don't handle it in any special way, such as Internet Explorer 10. I can't afford to show yyyy-mm-dd dates to my users, so I thought that I would rather feed my input tags user-friendly formatted dates, such as dd/MMM/yyyy (that's the format we use over here). But then, this works OK on browsers that handle it as simple text, like Internet Explorer; on Safari on iOS 7, which expects a proper RFC 3339 full date, the date type input tag appears blank.

所以我卡住了。我想我需要一种方法来手动处理个别浏览的支持,并在程序根据是什么浏览器客户端使用格式化我的日期。我的问题是:

So I am stuck. I guess I need a way to manually handle browse support individually, and programmatically format my dates according to what browser the client is using. My questions are these:


  • 请我真的需要做到这一点,还是有解决方法吗?

  • 如果我需要做的是,可以请你提出一个简单的方法?我使用ASP.NET,C#和Bootstrap 3。

我宁愿不引入更多的框架,如Modernizr的正好解决了这一问题。我随时可以回去使用纯文本标签,如果这是太困难或麻烦来解决。

I would rather avoid introducing additional frameworks such as modernizr just to solve this problem. I can always go back to using plain text tags if this is too difficult or cumbersome to fix.

感谢您。

推荐答案

请参见这个。它建议2 polyfills。 这一次和<一个href=\"http://www.useragentman.com/blog/2010/07/27/creating-cross-browser-html5-forms-now-using-modernizr-webforms2-and-html5widgets-2/\"相对=nofollow>这个。这两个看起来pretty不错。做浏览器检测则特殊的格式是凌乱的,所以我不建议这样做。

See this. It recommends 2 polyfills. This one and this one. Both look pretty good. Doing browser detection then special formatting is messy, so I don't recommend it.

这篇关于处理特定的浏览器支持HTML INPUT TYPE =&QUOT的;日期和QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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