javascript IE9 相当于 querySelectorAll
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13171247/
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
IE9 equivalent of querySelectorAll
提问by Fibericon
I haven't had any problems in FF or Chrome, but IE9 chucks an error on this method. I thought I would be able to use it, due to it having been shown to be supported here:
我在 FF 或 Chrome 中没有遇到任何问题,但 IE9 在此方法上出现错误。我以为我可以使用它,因为它已被证明在此处受支持:
http://www.quirksmode.org/dom/w3c_core.html
http://www.quirksmode.org/dom/w3c_core.html
However, that appears to not be the case in practice. That being said, what can I use in its place?
然而,在实践中似乎并非如此。话虽如此,我可以用什么来代替它?
EDIT: Here's the exact line it fails on:
编辑:这是它失败的确切行:
var maximize_buttons = document.querySelectorAll(".maximize");
That is the first time I attempt to use querySelectorAll(). The browser version number is 9.0.8112.16421
那是我第一次尝试使用 querySelectorAll()。浏览器版本号为 9.0.8112.16421
EDIT (again): I've verified this error on two separate computers. However, there's one thing in common that they share - they're both running Windows 7 on VMware. Is that relevant?
编辑(再次):我已经在两台不同的计算机上验证了这个错误。但是,它们有一个共同点——它们都在 VMware 上运行 Windows 7。这有关系吗?
Browser mode was IE9, but document mode was set to quirks by default. Changing it to Internet Explorer 9 standards fixed the problem, but if quirks is default, I still need to make it work for that.
浏览器模式是 IE9,但文档模式默认设置为 quirks。将其更改为 Internet Explorer 9 标准解决了该问题,但如果 quirks 是默认设置,我仍然需要让它为此工作。
回答by macguru2000
You need to use the html5 doctype for IE9 to work with the querySelectorAll() javascript method. The doctype looks like this and should be placed as the first line on all the pages in your site.
您需要使用 IE9 的 html5 doctype 才能使用 querySelectorAll() javascript 方法。doctype 看起来像这样,应该放在站点中所有页面的第一行。
<!DOCTYPE html>
回答by T.J. Crowder
This has nothing to do with quirks vs. standards mode, as the other answers suggest.
正如其他答案所暗示的那样,这与怪癖与标准模式无关。
It has to do with so-called "Compatibility Mode." IE9 through IE11 use "Compatibility Mode" with intranet sites by default, and with other sites according to your settings.
它与所谓的“兼容模式”有关。默认情况下,IE9 到 IE11 对 Intranet 站点使用“兼容模式”,并根据您的设置对其他站点使用“兼容模式”。
To tell IE that your site actually uses web standards and it shouldn't hobble itself, either:
告诉 IE 您的网站实际上使用网络标准并且它不应该阻碍自己,或者:
Update your server config to send the
X-UA-Compatible
header with the valueIE=Edge
, orAdd it as a
meta
tag right at the top of yourhead
element markup:<meta http-equiv="X-UA-Compatible" content="IE=Edge">
更新您的服务器配置以发送
X-UA-Compatible
带有值的标头IE=Edge
,或者将其作为
meta
标签添加到head
元素标记的顶部:<meta http-equiv="X-UA-Compatible" content="IE=Edge">
Of course, you should have a doctype as well, but just a doctype won't deal with the (in)Compatibility Mode issue.
当然,你应该有一个DOCTYPE以及,但只是一个DOCTYPE不会与(中)兼容模式问题处理。
回答by Norguard
Running quirksmode is like running non-standard IE6.
运行 quirksmode 就像运行非标准的 IE6。
You must, must, must(!) have a doctype on top of each HTML page: <!doctype html>
Every relevant (and many irrelevant) browser supports it.
And without it... ...well... quirksmode...
您必须,必须,必须(!)在每个 HTML 页面顶部都有一个 doctype:<!doctype html>
每个相关(以及许多不相关)浏览器都支持它。
没有它...... ......好吧...... quirksmode......
You don't want to be running in quirksmode for anything, ever, as you never know what kind of JS/CSS/html5 support is suddenly going to disappear or act weird...
你永远不想在 quirksmode 中运行任何东西,因为你永远不知道什么样的 JS/CSS/html5 支持会突然消失或表现得很奇怪......
So don't do it.
所以不要这样做。