简体   繁体   English

IE8不支持querySelectorAll

[英]IE8 does not support querySelectorAll

I tried to use document.querySelectorAll() , but IE8 throw error, that 我试图使用document.querySelectorAll() ,但IE8抛出错误,那

Object doesn't support this property or method Object不支持此属性或方法

var titleCheckBox = document.querySelectorAll("");

Here http://www.quirksmode.org/dom/w3c_core.html#t13 written, that IE8 support this method. 这里写的http://www.quirksmode.org/dom/w3c_core.html#t13,IE8支持这种方法。 What I doing wrong? 我做错了什么?

Check that your page isn't in Quirks mode or Compatibility mode. 检查您的页面是否处于Quirks模式或兼容模式。 You can use the F12 dev tools to confirm this. 您可以使用F12开发工具进行确认。 Press F12 and look in the top-right corner of the resulting window. 按F12并查看生成窗口的右上角。 If you see "Compatibility" or "Quirks" in the mode description, then you've found the problem. 如果您在模式说明中看到“兼容性”或“怪癖”,那么您就发现了问题。

  • Quirks mode: this is usually triggered by a missing or broken Doctype. Quirks模式:这通常是由缺少或损坏的Doctype触发的。 If this is the case, make sure your page starts with the following: 如果是这种情况,请确保您的页面以下列内容开头:

     <!DOCTYPE html> 
  • Compatibility mode (IE7 mode): This may be triggered if you're viewing the page locally (ie running it on your local machine, eg for testing, or on your local network). 兼容模式(IE7模式):如果您在本地查看页面(即在本地计算机上运行,​​例如进行测试,或在本地网络上),则可能会触发此操作。 In this case, you are being hit by an IE config setting that you should disable. 在这种情况下,您将被要禁用的IE配置设置命中。 Go to the Tools menu, and pick the Comaptibility View Settings option. 转到“工具”菜单,然后选择“Comaptibility视图设置”选项。 Untick the compatibility options, and the page should start working. 取消兼容性选项,页面应该开始工作。

    Compat mode may also be triggered (or avoided) by an X-UA-Compatibility meta tag. 也可以通过X-UA-Compatibility元标记触发(或避免)Compat模式。 If you're having trouble with compatibility mode, this is a good way to avoid it: Add the following line to your code: 如果您在兼容模式下遇到问题,这是避免它的好方法:在代码中添加以下行:

     <meta http-equiv="X-UA-Compatible" content="IE=edge"> 

Either (or both) of the above could be the problem, but my guess is that the problem is compatibility mode. 上述任何一个(或两个)都可能是问题,但我的猜测是问题是兼容模式。 The compat-mode-on-intranet-sites setting is suprisingly little known, and catches a lot of people out, even some seasoned developers. 内部网站上的compat-mode-onnet设置令人惊讶地鲜为人知,并且吸引了很多人,甚至是一些经验丰富的开发人员。

IE8 only supports querySelectorAll() in standards mode. IE8仅支持标准模式下的querySelectorAll() From MSDN : 来自MSDN

The Selectors API is defined as part of the Selectors API specification and is only available to Web pages displayed in IE8 standards mode. Selectors API被定义为Selectors API规范的一部分,仅适用于以IE8标准模式显示的网页。

Chances are your page doesn't have a proper DOCTYPE declaration; 您的页面可能没有正确的DOCTYPE声明; you will need to add one. 你需要添加一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM