使“datetime-local”类型的 html5 输入字段与 Firefox 兼容

a.n*_*rea 8 html firefox compatibility angularjs

我在基于 AngularJS 的界面中使用了一些 HTML5 日期和时间输入字段:

<input type="datetime-local" ng-model="event.date_time.start" />
<input type="week" ng-model="event.date_time.start" />
Run Code Online (Sandbox Code Playgroud)

我需要使这个界面与不支持这些类型的输入字段的 Firefox 兼容。

通过JavaScript检测浏览器并相应地显示不同的字段是最好的还是有办法让它兼容?

Mar*_*nes 3

比检测浏览器本身更好的是检测浏览器和版本是否与某些输入类型兼容。

幸运的是,有一些简单的方法可以做到这一点。我喜欢使用Modernizr

下面的代码显示了如何测试浏览器是否支持datetime-local使用 Modernizr,如果不支持,则应用名为 的 jQuery.ui 插件datetimepicker

<script>
    <!--
    if(!Modernizr.inputtypes['datetime-local']) {
        $('input[type=datetime-local]').datetimepicker();
    }
    -->
</script> 
Run Code Online (Sandbox Code Playgroud)