点击语音气泡按顺序显示列表项目-在IE8中不工作

Click speech bubble to display list items in order - Not working in IE8

本文关键字:IE8 工作 项目 列表 语音 气泡 显示 顺序      更新时间:2023-09-26

我有一个列表在我的HTML与一些引号。我也有一个名为"演讲"的div样式看起来像一个演讲泡沫。

当程序运行时,第一个引号显示在气泡中,当点击它时,它跳过引号列表。

我的问题是,在IE8没有显示在泡沫,我不知道为什么。谁能告诉我我是否做错了什么,或者建议我如何做得更好?

这是清单…

<ul class="facts">
        <li>
            <span>What goes ho-ho whoosh, ho-ho whoosh?<br/>Santa caught in a revolving door.</span>
        </li>
        <li>
            <span>Whats white and goes up? <br/> A confused snowflake.</span>
        </li>
        <li>
            <span>Which Christmas carols do parents like best? <br/> Silent Night.</span>
        </li>
        <li>
            <span>How did the snowman get to school?<br/>On his icicle.</span>
        </li>
        <li>
            <span>What do you call a three-legged donkey?<br/> A wonkey.</span>
        </li>
</ul>

,这里是脚本…

jQuery.fn.extend({
rnditem : function(l) {
    var a = [],
        current = jQuery(this).html().trim(),
        index,
        next;
   Array.prototype.forEach.call(l, function(item) {
        a.push(jQuery(item).html()
               jQuery.trim();
   });
   index = a.indexOf(current) + 1;
   if (index < 0 ||  index >= l.length) {
       index = 0;
   }
   next = (l.eq(index).html());
   jQuery(this).html(next);
  return this;
   }
});
    jQuery(document).ready(function () {

var list = jQuery(".facts").find("li");
jQuery(document.body).on('click','.speech', function () {
jQuery(this).rnditem(list);
});
jQuery(".speech").trigger("click");

});

小提琴:http://jsfiddle.net/S79qp/425/

看小提琴,我看到的代码与上面发布的不同。

下面的行
current = jQuery(this).html().trim(),

a.push(jQuery(item).html().trim());

会抛出类似于

的错误

对象不支持'trim'属性或方法

因为IE8没有内置修剪,所以使用jQuery.trim()