0

我的网页没有<main class="page-content"></main>在 IE8 中渲染标签中的内容。我正在使用backbone.js框架,并且我有一个将元素附加到页面上的视图。我也使用 html5shiv。

第一个元素追加只是找到(导航栏及其所有元素);但是,IE8 在尝试追加.page-content元素时会引发错误。我已将此问题追溯到 jQuery 的 find 方法中的不一致。仅在 IE8 中,当对包含标签的 DOM 执行 a 时,该方法返回一个属性设置为.find('.page-content')的元素。请注意,缺少结束标记(以及所有内部元素)。这只发生在 IE8 中(我还没有测试过 >IE8),当它发生时,它会导致方法在 jQuery 的方法中失败。.outerHTML<MAIN class=page-content>appendChild()append()

深入挖掘了jQuery的find方法,发现问题的根源是jQuery使用Web API方法的时候querySelectorAll()。在 jQuery 的代码中,开发人员评论如下:

// qSA works strangely on Element-rooted queries
// We can work around this by specifying an extra ID on the root
// and working up from there (Thanks to Andrew Dupont for the technique)
// IE 8 doesn't work on object elements

但是,我真的不知道这意味着什么......

我创建了一个 jsFiddle 示例来演示这个问题:http: //jsfiddle.net/VHL7Q/6/

如果您在 IE8 中打开 jsFiddle 链接,将显示警报:

<MAIN class=page-content>

或者,如果您在 Chrome 或 Firefox 中打开 jsFiddle 链接,将显示警报:

<main class="page-content">
    <div class="help-toggle">
        <i class="icon-info-sign"></i>
    </div>
</main>

没有纠正我自己的 find 遍历 DOM 树的方法,我不知道如何开始解决这个问题。

注意:似乎有效的“创可贴”类型的解决方案是用标签替换<main></main>标签<div></div>。但是,我不能永久使用此解决方案;我需要帮助找到使用<main></main>标签的方法。

4

2 回答 2

1

问题是 IE8 不完全支持 HTML5。特别是,它不知道元素main是什么。

其中一些问题可以通过使用来解决HTML5 Shim,但我不知道它是否 100% 兼容。

链接说明:( 简而言之,shimdocument.elementCreate为所有新的 HTML5 元素运行 a,以启动IE8它们的存在。)

于 2014-04-07T20:16:46.773 回答
0

After six days of digging, I did what I should have done on day one. I updated my html5shiv and modernizr to their newest versions. Specifically I updated html5shiv from 3.6.1 to 3.7.0, and I updated modernizr from 2.5.3 to 2.7.1.

This does not directly answer my questions about the detailed functionality of jQuery and Web API, but it can be assumed that the newest version of a library might fix your problems with a five year old software product.

Thank you Jeremy and cookie monster for your help.

于 2014-04-08T22:27:16.350 回答