javascript 所有浏览器都支持 querySelector 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3856294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is querySelector supported by all browsers?
提问by KoolKabin
I would like to know is querySelectorsupported by all browsers? is not what's alternate for it to use?
我想知道所有浏览器都支持querySelector吗?不是它可以使用的替代品吗?
I have tested it with IE8, FF3, Chrome 4. Its fine for me. I do not have old browsers. So i would like to know if old browsers will give problem to me or not?
我已经用 IE8、FF3、Chrome 4 对其进行了测试。对我来说很好。我没有旧浏览器。所以我想知道旧浏览器是否会给我带来问题?
回答by annakata
IE7< don't support it and IIRC IE8 has issues with namespaces. There's at least one more esoteric browser out there with major issues but I don't recall which it is.
IE7< 不支持它,而 IIRC IE8 有命名空间问题。至少有一个更深奥的浏览器存在重大问题,但我不记得是哪个。
Basically there is no unified expression-based DOM method, and absolutely your best bet is to use a library (the ubiquitous "use jquery" answer, but you should at least check out Sizzleif you have a problem with large libraries) because rolling your own is more effort than reasonably worthwhile (I speak from experience).
基本上没有统一的基于表达式的 DOM 方法,绝对你最好的选择是使用一个库(无处不在的“使用 jquery”答案,但如果你有大型库的问题,你至少应该检查一下Sizzle)因为滚动你的自己的努力比合理的值得(我是根据经验说的)。
回答by Sachin Shanbhag
QuerySelector is supported on Firefox 3.1+, IE8+ (only in IE8 standards mode), and Safari 3.1+ browsers.
Firefox 3.1+、IE8+(仅在 IE8 标准模式下)和 Safari 3.1+ 浏览器支持 QuerySelector。
回答by Milinda Bandara
I tested it with FireFox - It is perfectly work. In IE there is a issue when you use the document with quirk mode (without using DOCTYPE HTML)
我用 FireFox 对其进行了测试 - 它非常有效。在 IE 中使用带有 quirk 模式的文档时会出现问题(不使用 DOCTYPE HTML)
Try to use in the HTML document
尝试使用 在 HTML 文档中
回答by Weijing Jay Lin
You can check MDN for detail information.
您可以查看 MDN 以获取详细信息。
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
| ------------- | ------ | ---------------- | ----------------- | ----- | --------------- |
| Basic support | 1 | 3.5 | 8 | 10 | 3.2 |
回答by Matt Ball
The bestalternative is to use a third-party library that abstracts all that nasty browser-specific code away, like YUI or jQuery (I'm not as familiar with Prototype et al, so I can't say for sure if it uses the query*methods [when available]).
在最好的选择是使用抽象所有讨厌的浏览器特定的代码,第三方库走,像YUI或jQuery的(我不熟悉的原型等,所以我不能肯定地说,如果使用query*方法[如果可用])。

