2013-06-27 47 views
0

打破jQuery的所以我用這個函數()功能在IE

months = months.filter(function(e, p) { return months.indexOf(e) == p; }); 

和測試alert();作品只有前。如果我把alert()放在這個函數的下面,它就不再工作了......
這隻發生在IE中,在Chrome中它很好。這打破了它下面的每個jquery。你可以看到現場的問題Here

而且,直接鏈接到js文件是Here

此功能有過濾重複months從李德全data-mes屬性在該網頁上...我有不知道爲什麼會這樣,也,我用這:

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 

但是,aparently在這個問題沒有效果....

下面是這個問題的全部代碼:

// gets all `data-mes` into an array 
var months = $('#gride li').map(function() { return $(this).data('mes'); }).get(); 

// remove repeated meses 
months = months.filter(function(e, p) { return months.indexOf(e) == p; }); 

// sorts the months 
var order = ['janeiro','fevereiro','março','abril','maio','junho','julho','agosto','setembro','outubro','novembro','dezembro']; 
orderedMonths = months.sort(function(a,b){ return order.indexOf(a) - order.indexOf(b); }); 

// add them, ordered, to the <select> with id #selectMes 
$.each(orderedMonths, function(_, v) { 
    $('#selectmes').append($('<li class="filter" data-filter="'+ v +'">').val(v).text(v)); 

}); 

回答

1

使用jQuery inArray

months = months.filter(function(e, p) { return $.inArray(e, months) == p }); 

Array.indexOf不支持IE9以下。

您有array.filter也是一個問題,因爲過濾器將不會在IE9工作的下方,而是使用$.grep

months = $.grep(months,function(e, p) { return $.inArray(e, months) == p }); 

Demo

+0

非常感謝你,不幸的是,這段代碼沒有工作... – user1576978

+0

我編輯了這個部分的全部js的問題,如果你可以看看 – user1576978

+0

@ user1576978任何機會你有什麼錯誤得到些什麼?試試這個'months.filter(function(e,p,arr){return $ .inArray(e,arr)== p});' – PSL

0

indexOf與IE無法正常工作。編寫你自己的,或者因爲你已經在你的網頁上有jQuery。使用jQuery方法: http://api.jquery.com/jQuery.inArray/

+0

謝謝..我閱讀inArray( )現在,是否有可能幫助我將月=行轉換爲inArray()而不是indexOf? – user1576978