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

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

问题描述

我使用HTML5元素输入属性,只有Google Chrome支持日期和时间属性。我尝试了 Modernizr ,但我无法理解如何将其集成到我的网站上(关于如何编码它/什么是语法/ includes)。任何关于如何使用日期,时间属性到所有浏览器的代码片段。

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();
}

FIDDLE

你当然可以使用任何你想要的日期选择器,jQuery UI的datepicker可能一个最常用的,但它确实增加了相当多的JavaScript,如果你不使用UI库的其他任何东西,但有几百个可供选择的日期选择。

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.

类型属性不会改变,浏览器只会回退到属性的默认文本类型,所以必须检查属性。

该属性仍然可以用作选择器,如上例所示。

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天全站免登陆