【问题标题】:IE7 & 8 throwing errors with jQuery's .sliceIE7 & 8 使用 jQuery 的 .slice 引发错误
【发布时间】:2012-10-03 09:21:55
【问题描述】:

以下代码在其他浏览器上运行良好,但在 IE7 和 8 上却报错:

    var divs = $(".paginate-boxes li");
        for(var i = 0; i < divs.length; i+=9) {
          divs.slice(i, i+9).wrapAll("<li class='slide-portfolio'><ul></ul></li>");
        }

它正在处理的代码是一长串lis,如下所示:

                        <li>
                                <!--Fade-->
                                <div class="mosaic-block fade">
                                    <a href="http://www.example.com/destination/" class="mosaic-overlay">
                                        <object class="details">

                                            <h4>Destination Page</h4>
                                            <p>
                                                                                                </p>
                                        </object>
                                    </a>
                                    <div class="mosaic-backdrop"><img width="296" height="175" src="http://www.example.com/wp-content/uploads/this_thumb.jpg" class="attachment-portfolio-image wp-post-image" alt="this_thumb" title="This image" /></div>
                                </div>
                            </li>

在 IE9(8 模式)中使用开发工具,我发现它在到达代码的 .slice 位时会报错,引用此位 jQuery (v.1.7.2)

// IE6-8 fail to clone children inside object elements that use
// the proprietary classid attribute value (rather than the type
// attribute) to identify the type of content to display
if ( nodeName === "object" ) {
    dest.outerHTML = src.outerHTML;
}

不知道这到底是什么意思

我需要改变什么来阻止它抛出错误,为什么?

【问题讨论】:

  • 看起来可能是wrapAll,而不是.slice()
  • 您尝试过当前版本的 jQuery 吗?这可能是一个已修复的错误。
  • 请使用非缩小的 jQuery 版本来调试 jQuery 错误
  • 等等...您正在选择&lt;li&gt; 元素,但您将变量命名为divs?这只是令人困惑。但是随后您尝试将这些&lt;li&gt; 元素的组包装在另一个&lt;li&gt; 中。那只是无效的 HTML。
  • @user1689607:完全正确,我的 HTML 无效。我已修复它,但我仍然收到错误。

标签: javascript jquery internet-explorer-8 internet-explorer-7 slice


【解决方案1】:

回想起来相当明显 - 将 &lt;object&gt; 替换为 &lt;div&gt; 并且效果很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    • 2012-01-03
    • 1970-01-01
    • 2010-12-15
    相关资源
    最近更新 更多