2013-04-23 14 views
0

我的HTML列表中有一些引號。我還有一個叫做「演講」的div,它的風格看起來像一個講話泡泡。點擊講話泡泡按順序顯示列表項目 - 不能在IE8中工作

程序運行時,第一個報價顯示在氣泡中,當它被點擊時,它跳過引號列表。

我的問題是,在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/

+0

爲什麼小提琴和代碼在這裏不同? – epascarello 2013-04-23 16:01:18

回答

1

望着小提琴,我看到不同的代碼比上面發佈的內容。

下面

current = jQuery(this).html().trim(), 

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

的線條會拋出,這將是像

對象不支持屬性或方法錯誤 '修剪'

因爲IE8沒有內置修剪,所以使用jQuery.trim()

+0

對不起,錯了。我現在改變了它,所以它應該匹配。我會在哪裏放「jQuery」? @Epascarello – sMilbz 2013-04-23 16:07:17

+0

你看過我鏈接過的jQuery trim文檔嗎?根據例子。 – epascarello 2013-04-24 12:47:18