如何制作<input type="date">所有浏览器都支持吗?任何替代方案? [英] How to make <input type="date"> supported on all browsers? Any alternatives?

查看:37
本文介绍了如何制作<input type="date">所有浏览器都支持吗?任何替代方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理 HTML5 元素的输入属性,只有 Google Chrome 支持日期、时间属性.我试过 Modernizr 但我不明白如何将它集成到我的网站上(关于如何编码/什么是语法/包括).关于如何处理所有浏览器的日期、时间属性的任何代码片段.

I'm working with HTML5 elements input attributes and only Google Chrome supports the date, time attributes. I tried Modernizr but I can't understand on how to integrate it on my website(on how to code it/what is the syntax/includes). Any code snippet there on how to work with date, time attributes to all browsers.

推荐答案

任何不支持输入类型 date 的浏览器都会默认为标准类型,即 text>,所以你要做的就是检查类型属性(不是属性),如果不是date,则输入的日期不是浏览器支持,您可以添加自己的日期选择器:

Any browser that does not support the input type date will default to the standard type, which is text, so all you have to do is check the type property (not the attribute), if it's not date, the date input is not supported by the browser, and you add your own datepicker:

if ( $('[type="date"]').prop('type') != 'date' ) {
    $('[type="date"]').datepicker();
}

小提琴

您当然可以使用任何您想要的日期选择器,jQuery UI 的日期选择器可能是最常用的一种,但如果您不将 UI 库用于其他任何用途,它确实会添加相当多的 javascript,但有数百种可供选择的其他日期选择器.

You can of course use any datepicker you want, jQuery UI's datepicker is probably the one most commonly used, but it does add quite a bit of javascript if you're not using the UI library for anything else, but there are hundreds of alternative datepickers to choose from.

type 属性永远不会改变,浏览器只会回退到默认的 text 属性类型,所以必须检查属性.
该属性仍可用作选择器,如上例所示.

The type attribute never changes, the browser will only fall back to the default text type for the property, so one has to check the property.
The attribute can still be used as a selector, as in the example above.

这篇关于如何制作<input type="date">所有浏览器都支持吗?任何替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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