为什么IE11处理减号符号的Node.normalize()不正确? [英] Why Does IE11 Handle Node.normalize() Incorrectly for the Minus Symbol?

查看:189
本文介绍了为什么IE11处理减号符号的Node.normalize()不正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Node.normalize()函数连接相邻的文本节点时,我遇到了一个问题,即DOM文本节点在某些字符中会出现奇怪的情况。

I have been experiencing an issue where DOM text nodes with certain characters behave strangely in IE when using the Node.normalize() function to concatenate adjacent text nodes.

我创建了一个Codepen示例,允许您重现IE11中的错误: http://codepen.io/anon/pen/BxoKH

I have created a Codepen example which allows you to reproduce the bug in IE11: http://codepen.io/anon/pen/BxoKH

IE11中的输出:' - 示例'

Output in IE11: '- Example'

Chrome和早期版本的IE输出: 'Test - Example'

Output in Chrome and earlier versions of IE: 'Test - Example'

正如你所看到的,这个截断在减号之前的所有东西,这显然被视为一个分界符,显然是由于本机的一个错误在Internet Explorer 11(但不是IE10或IE8甚至IE6)中执行normalize()。

As you can see, this truncates everything prior to the minus symbol which is apparently treated as a delimiting character, apparently due to a bug in the native implementation of normalize() in Internet Explorer 11 (but not IE10, or IE8, or even IE6).

任何人都可以解释为什么会发生这种情况,有没有人知道导致这个问题的其他字符序列?

编辑 - 我已经编写了一个将测试sec Unicode字符来识别导致此行为的字符。似乎会影响比我原来意识到的更多的角色:

Edit - I have written a codepen that will test sections of Unicode characters to identify characters that cause this behavior. It appears to affect many more characters than I originally realized:

http: //codepen.io/anon/pen/Bvgtb/ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $我要创建一个IE错误报告,并且Microsoft报告能够复制,但是请注意IE中的范围太多,否则会冻结。

http://codepen.io/anon/pen/Bvgtb/ This tests Unicode characters from 32-1000 and prints those that fail the test (truncate data when nodes are normalized) You can modify it to test other ranges of characters, but be careful of increasing the range too much in IE or it will freeze.

它基于我提供的代码示例。如果您还遇到此问题,请投票:
https://connect.microsoft.com/IE/feedback/details/832750/ie11-node-normalize-dom-implementation-truncates- data-when-adjacent-text-nodes-contain-a-minus-sign

I've created an IE bug report and Microsoft reports being able to reproduce it based on the code sample I provided. Vote on it if you're also experiencing this issue: https://connect.microsoft.com/IE/feedback/details/832750/ie11-node-normalize-dom-implementation-truncates-data-when-adjacent-text-nodes-contain-a-minus-sign

推荐答案

有些冗长和不完整 - 他们不走完整个DOM子树。这是一个更全面的解决方案:

The other answers here are somewhat verbose and incomplete — they do not walk the full DOM sub-tree. Here's a more comprehensive solution:

function normalize (node) {
  if (!node) { return; }
  if (node.nodeType == 3) {
    while (node.nextSibling && node.nextSibling.nodeType == 3) {
      node.nodeValue += node.nextSibling.nodeValue;
      node.parentNode.removeChild(node.nextSibling);
    }
  } else {
    normalize(node.firstChild);
  }
  normalize(node.nextSibling);
}

这篇关于为什么IE11处理减号符号的Node.normalize()不正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆