对于移动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
更多推荐
检测浏览器的本机日期/时间选择器
发布评论