检测日期和日期时间类型的输入类型支持

Detecting input type support of date and datetime types?

本文关键字:类型 日期 输入 支持 时间 检测      更新时间:2023-09-26

我尝试使用Modernizr来检测对datedatetime输入字段(HTML5)的支持,但这些变量总是返回false,即使它们被支持(即在Chrome中):

if(Modernizr.inputtypes.datetime) {
    jQuery("#what").html("Yes, I know datetime input fields.");
} else {
    jQuery("#what").html("Sorry, what is a datetime input field?");
}
#what {
    padding : 2em;
    margin  : 2em;
    text-align : center;
    
    border : 1px solid #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="what">Well... I'm not sure.</div>

通过研究这个问题,似乎这个错误是一个老习惯。

我怎么解决它?

chromefirefox不支持datetime

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime

以后可以使用:https://developer.mozilla.org/

使用Modernizr.inputtypes['datetime-local']Modernizr.inputtypes['date']代替

我认为您之后的是if (Modernizr.inputtypes.date)而不是datetime,因为没有名为datetime的输入类型