HTML5 日期输入类型干扰 jQuery Datepicker [英] HTML5 Date Input Type Interfering with jQuery Datepicker
问题描述
我在我的网站上使用 jQuery UI 的日期选择器进行日期选择.我的一位用户刚刚升级到最新版本的 Chrome,它内置了 HTML5 的原生日期选择器.两个 UI 相互重叠的大问题.另一个问题是当用户提交日期时,数据库中的日期恢复为0000-00-00"并且产生了错误数据.
I am using the jQuery UI's datepicker for date selections on my site. One of my users just upgraded to the newest version of Chrome, which has built-in native date picker for HTML5. The big problem as the two UIs overlap each other. The other problem is when the user submits a date, the date in database reverts to "0000-00-00" and is producing bad data.
如果我删除 jQuery 日期选择器,大多数不使用最新浏览器的用户将不会有弹出式日期选择器.而且,那些拥有最新浏览器的人将有两个重叠的日历,这会破坏应用程序.我的问题是如何禁用最新的浏览器显示内置日期功能并继续使用 jQuery Datepicker?
If I remove the jQuery datepicker, most of the users not using the latest-greatest browsers will not have a popup date picker. And, those who have the newest browser will have two overlapping calendars which breaks the application. My question is how do I disable the newest browsers from displaying the built-in date function and just continue to use the jQuery Datepicker?
推荐答案
使用 Modernizr 或类似的库来特征检测是否浏览器支持input type=date
,如果不支持则加载jQuery UI datepicker.
Use Modernizr or similar library to feature detect if the browser supports the input type=date
, and then load the jQuery UI datepicker if if does not.
if (!Modernizr.inputtypes.date) {
$('input[type=date]').datepicker();
}
这篇关于HTML5 日期输入类型干扰 jQuery Datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!