如何检测浏览器是否支持指定的css伪类?
通过 JavaScript 检测浏览器对任何 css 伪类的支持是什么概念?确切地说,我想检查用户的浏览器是否支持 :checked
伪类,因为我制作了一些带有复选框的 CSS 弹出窗口,并且需要对旧浏览器进行回退。
What's concept of detecting support of any css pseudo-class in browser through JavaScript? Exactly, I want to check if user's browser supports :checked
pseudo-class or not, because I've made some CSS-popups with checkboxes and needs to do fallbacks for old browsers.
ANSWER: I'm found already implemented method of testing css selectors in a Modernizr "Additional Tests".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于仍在寻找此问题的快速解决方案的人,我根据本线程中的其他一些答案整理了一些内容。我的目标是使其简洁。
For anyone still looking for a quick solution to this problem, I cribbed together something based on a few of the other answers in this thread. My goal was to make it succinct.
您可以简单地检查是否应用了带有伪类的样式。
像这样的东西: http://jsfiddle.net/qPmT2/1/
You can simply check if your style with pseudo-class was applied.
Something like this: http://jsfiddle.net/qPmT2/1/
stylesheet.insertRule(rule, index) 方法将如果规则无效,则抛出错误。所以我们可以使用它。
stylesheet.insertRule(rule, index) method will throw error if the rule is invalid. so we can use it.
如果您可以使用 Javascript,则可以跳过检测并直接使用填充程序:Selectivizr
If you're OK with using Javascript, you might skip the detection and go right for the shim: Selectivizr