通过jQuery检测对特定HTML 5功能的支持 [英] Detecting support for specific HTML 5 features via jQuery
问题描述
我正在制作一些HTML5演示代码,包括< input type =date/>
I'm working on some HTML5 demo code, including stuff like <input type="date" />
这当前在Opera 10中正常工作,但每个其他浏览器只显示正常的文本输入。然后我使用jQuery.date-input插件在不支持它的浏览器上覆盖此行为。
This currently works correctly in Opera 10 as-is, but every other browser just displays a normal text input. I'm then using a jQuery.date-input plugin to override this behaviour on browsers that don't support it.
问题是 - jQuery也在Opera上运行,所以在Opera中我得到两个日历日期选择器(一个来自浏览器,一个来自jQuery)
Problem is - the jQuery's running on Opera as well, so in Opera I'm getting two calendar date-pickers (one from the browser, one from jQuery)
我现在可以使用<$ c $解决这个问题c> if(window.opera) - 但是有没有办法使用jQuery.support,我可以可靠地检测当前浏览器是否支持特定的HTML5功能?
I can work around this for now using if (window.opera)
- but is there some way using, say, jQuery.support, that I can reliably detect whether the current browser supports a particular HTML5 feature or not?
推荐答案
我想看看 Modernizr 。它是一个开源的,麻省理工学院授权的Javascript库,可以检测对许多HTML5 / CSS3功能的支持,它非常小(7kb压缩)。要使用它,只需:
I would take a look at Modernizr. It's an open source, MIT-licensed Javascript library that detects support for many HTML5/CSS3 features and it's REALLY tiny (7kb compressed). To use it, simply:
<script src="modernizr.min.js"></script>
在您的< head>
内文件。之后,它具有各种功能来检查您的需求。示例:
Within the <head>
of your document. After that, it has a variety of functions to check for what you need. Example:
if (Modernizr.canvas) {
// do stuff
}
还有很多方法可以检查您想要的特定HTML5 / CSS3功能。 查看他们的网站以获取它并查看文档。
There's many more ways to check for the specific HTML5/CSS3 feature you'd like. Check out their website to get it and see the docs.
这篇关于通过jQuery检测对特定HTML 5功能的支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!