IE11和querySelector问题 [英] IE11 and querySelector issue
问题描述
我在DIV中的页面上,内容可以在某些文本上编辑。在本文中,我需要获取所有 P
元素的值(由用户编写的文本),但我需要排除所有span元素(不用于其余部分的变量)我必须做的工作)。
I got on my page inside a DIV with content editable on some text. In this text I need to get the value of all P
elements (text written by user) but I need to exclude all span elements (variables that are not used for the rest of the work I have to do).
我试图在IE11中使用querySelector来做这件事,但这里是交易:对于IE11,querySelector不存在,即使我监视元素并告诉我这个方法存在(使用F12并在其上放一个间谍)。我该怎么做才能纠正这个问题?我试过在这个论坛上找到的东西可以说:
I tried to do it using querySelector in IE11 but here is the deal : For IE11 querySelector doesn't exist, even when I spy the element and it tell me this method exist (using F12 and putting a spy on it). What should I do to correct that ? I tried something I found on this forum that's say to put :
<meta http-equiv="X-UA-Compatible" content="IE=11" />
在文档的头部,但它不起作用。
in the Head of the document, but it did not work.
我用来做这个的JS是:
The JS I use to do this is :
function recupTXT(div) {
var textRecup = div.cloneNode(true);
while (textRecup.querySelector("span") !== null) {
textRecup.querySelector("span").parentNode.removeChild(textRecup.querySelector("span"));
}
return textRecup.innerText;
}
编辑:
他这样称呼:
var text = recupTXT(document.getElementById('edth_corps'));
其中edth_corps是内容可编辑生成的programmaticaly
where edth_corps is the content editable generated programmaticaly
如果我在一个独立的站点上尝试它,具有相同的条件(内容可编辑和东西),它工作得非常好,并做我需要的。但在我的应用程序中它失败了。那么它只是一个配置问题吗?或者有什么我遗失的东西?
If I try it on a stand alone, with the same condition (content editable and stuff), it work pretty fine and do what I need. But in my application it failed. So is it just a configuration issue ? or is there something I'm missing ?
推荐答案
你说文件模式是5
。
这意味着IE在Quirks模式下运行。此模式旨在模拟IE5,因此它禁用了自IE5以来发明的大多数浏览器功能,包括 querySelector
。
This means that IE is running in Quirks Mode. This mode is designed to emulate IE5, and as a result it disables most of the browser features invented since IE5, including querySelector
.
您可以通过阻止浏览器进入Quirks模式来解决问题。
You can resolve the problem by preventing the browser from going into Quirks Mode.
这是通过确保(1)您的HTML有效来实现的,并且(2)它有一个有效的doctype声明作为第一行。如果您没有doctype,请将以下内容添加到代码顶部:
This is achieved by making sure (1) that your HTML is valid, and (2) that it has a valid doctype declaration as the first line. If you don't have a doctype, add the following to the top of your code:
<!DOCTYPE html>
这篇关于IE11和querySelector问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!