检测浏览器的本机日期/时间选择器

编程入门 行业动态 更新时间:2024-10-25 16:21:05
本文介绍了检测浏览器的本机日期/时间选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

对于移动html5 / js网站,我希望在可用时利用本机浏览器日期/时间选择器(例如在移动设备上)。我知道我可以检测浏览器是否支持日期/日期时间输入类型,这有助于确保输入正确的数据格式,但有没有正确的方法来检测当前浏览器是否提供本机日期和/或时间选择器?

For a mobile html5/js website I would like to leverage native browser date/time pickers when available (like on mobile safari for instance). I know I can detect if the browser supports the date/datetime input types, which will help ensure the proper data format is entered, but is there a proper way to detect if the current browser offers native date and/or time picker?

推荐答案

你可以创建一个输入元素并尝试分配类型,如果不支持,类型将切换回默认类型(这是文本)

you can create an input element and try to assign the type, if it's not supported the type will switch back to the default type (which is text)

function isDateSupported() { var i = document.createElement("input"); i.setAttribute("type", "date"); return i.type !== "text"; }

或者您可以使用像 modernizr

更多推荐

检测浏览器的本机日期/时间选择器

本文发布于:2023-10-04 02:37:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467104.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:本机   浏览器   日期   时间   选择器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!