gpt4 book ai didi

javascript - 使用空白 :nowrap is one line in IE 在 PRE 中美化突出显示

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:29:07 24 4
gpt4 key购买 nike

在 Internet Explorer 中,一个 PRE风格为 white-space:nowrap导致 PRE 中的代码当我使用 prettify ( http://code.google.com/p/google-code-prettify/ ) 时在一行中。

不是 <br/>应该在 PRE 中产生一个新行?我在页面加载后检查了 prettify 生成的 HTML 源代码,它生成了 <br/>当它遇到换行符时。

参见 http://blog.mikecouturier.com/2009/12/google-street-view-with-google-maps_27.html举个例子。

这在 FF 和 Chrome 中都不会发生。

谢谢

编辑: 也许这与此有关:Inserting a newline into a pre tag (IE, Javascript)

最佳答案

来自 The Internet Explorer innerHTML Quirk :

The innerHTML property of HTML elements is well-known and widely used. It is capable of setting the complete content of an element in one go, including elements and the like. As the QuirksMode tests have shown, innerHTML is the fastest way to dynamically change the page content.

However, innerHTML has a problem in Internet Explorer.

The HTML standard requires a transformation on display of content. All kinds and amounts of adjacent whitespace are collapsed into a single space. This is a good thing - just as an example, it allows me to add a lot of line breaks into this source file without having to worry about weird line breaks in the displayed text.

Internet Explorer applies these transformations on assignment to the innerHTML property. This seems like a good idea: it saves a little time during display, because if the in-memory representation is already normalized, then the browser doesn't have to normalize whenever it needs to display the text.

There are exceptions to the normalization rule, though. Notably, these are the <textarea> element, the <pre> element and, in CSS-aware browsers, elements with any value but normal for the white-space property.

Internet Explorer does not respect these special cases. The third makes their optimization a bad idea, because white-space might change at runtime, for example through the DOM. In any case, Internet Explorer will normalize all assignments to the innerHTML property.

这是另一个 IE 独有的“错误”(即使是他们发明了 innerHTML)。在第一个链接中,您有解决此问题的方法,但正如 Lucas 指出的那样,所有内容似乎都指向您无法控制的 Google 代码。

关于javascript - 使用空白 :nowrap is one line in IE 在 PRE 中美化突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1970446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com