- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要与 textContent 等效的 IE。
在您跳出裤子之前——innerText 与 textContent 不同。 innerText 在 DOM 渲染器解析时解析空格。 textContent 在写入时解析空格。我需要后者,但 I.E.不支持文本内容。
例如:
DOM Obj: <p>This is an example.</p>
innerText: "This is an example."
textContent: "This is an example."
最佳答案
我认为你做不到。 IE 甚至在 TextNode#nodeValue
属性中“标准化”空格。前一段时间我写过这个:
function textValue(element) {
var collector = [];
textValueCollector(element, collector);
return collector.join("");
}
function textValueCollector(element, collector) {
var node;
for (node = element.firstChild; node; node = node.nextSibling)
{
switch (node.nodeType) {
case 3: // text
case 4: // cdata
collector.push(node.nodeValue);
break;
case 8: // comment
break;
case 1: // element
if (node.tagName == 'SCRIPT') {
break;
}
// FALL THROUGH TO DEFAULT
default:
// Descend
textValueCollector(node, collector);
break;
}
}
}
所以我认为这可能是您所需要的,但遗憾的是,不是。正如您在 this live example 中看到的那样,在 IE 上,即使我们直接遍历文本节点,额外的空格也会被忽略,所以它只显示 45 的长度,而实际上它是 61(在其他浏览器 [Chrome、Firefox、Opera] 上)。
关于用于 IE 的 Javascript textContent(保留空格的 innerText),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6826164/
有没有办法只获取顶部元素的 innerText(并忽略子元素的 innerText)? 例子: top node text child node text 如何在忽略“子节点文本”
我想获取 的 innerText没有 innerText在跨度内...这是页面的 HTML: var title = document.querySelector('div.col-md-8.inf
在这种情况下,我尝试使用关卡菜单,但是 this.innerText 不起作用 function levelJump() { console.log(this);// Window {wind
假设我有:return this value 基本上我想得到 的 innerText基于类名的标签。 问题是当我尝试:alert(document.getElementsByClassName("h
我有一个 html 元素,例如: Change only mebut not me 但我只想更改第一个文本并让子 div 保持原样 document.getElementById("el1").inn
1st Division 2016/2017
我有一些这样的HTML(我无法更改): Employee Name: John Smith 我想使用xpath提取“ John Smith”部
当节点在集合中时,有没有办法获取节点的内部文本目前我有这个 Collection DependentNodes = new Collection(); foreach (XmlNode node in
我想知道 innerText 属性。考虑以下标记: HTML foo bar 然后,让我们运行以下代码: JS var
我有一个包含一些文本的 div 和一个子 div。我想更新外部 div 文本并保留子 div。 some text here 如果我尝试 outer.innerText = "foo",向下
我的以下代码有错误。如果选择了元素(选择的类是选择的元素),我试图获取 id id05 的值。 HTML: t1
我写了这段代码: // Welcome to ASP.NET! 当我运行它时,出现此错误:无法设置未定义或空引用的属性“in
我们有这样的 XML: Some text here Child 1 Child 2 我们正在使用 XmlDocument 来解析它。 当我们有“节点”元素的 XmlNo
我如何将文本添加到 XML 元素中?例如: I want to add text here 我已经创建了 DOMDocument,并开始添加元素。这是我需要将文本添加到的元素。 $title = $v
假设您有一个按钮可以替换同一区域、同一页面内的段落。 您能否通过设置 innerText 或 textContent 使每次切换都淡入? 我现在使用 keyframes 将其不透明度从 0 更改为 1
我想问一下如何通过 Javascript 更改单选按钮的标签 innerText(见下面的代码)同时不清除输入标签里面。此处的标签 innerText 表示“Button-Label-X”。 我尝试通
我试图获取元素的 innerText,但 Chrome 返回一个空字符串,因为我的元素被隐藏了。 Firefox 没有。 即使元素不可见,是否有办法在 Chrome 中检索 innerText? co
刚从jQuery 1.3.2升级到1.8.2,发现1.3.2的几个功能不能用了。我已经修复了其中的大部分问题,但仍停留在这个问题上: 我需要根据表格单元格中的前几个字符进行搜索(“开头为”搜索),但此
假设我有以下代码: some text var d = document.getElementByid('d'); var innerText = d.inn
我正在尝试编写一个函数(在 JavaScript 中),它将在 中写一个句子例如,通过在每个字母之间停顿 300 毫秒,一个接一个地写入其字母来标记。我写了以下内容: var tex
我是一名优秀的程序员,十分优秀!