IE上的函数中断jquery

IE上的函数中断jquery,jquery,internet-explorer,compatibility,Jquery,Internet Explorer,Compatibility,所以我使用这个函数() 和一个测试alert()仅在它之前起作用。如果我将alert()放在这个函数下面的某个位置,它将不再工作这只发生在IE中,在Chrome中是可以的。这会打断它下面的每个jquery。你可以现场看到这个问题 此外,还提供了指向js文件的直接链接 此功能用于过滤重复的月份从本页li上的所有数据mes属性中获取。。。我不知道为什么会发生这种情况,我也在用这个: <meta http-equiv="X-UA-Compatible" content="IE=edge,chro

所以我使用这个函数()

和一个测试
alert()仅在它之前起作用。如果我将alert()放在这个函数下面的某个位置,它将不再工作
这只发生在IE中,在Chrome中是可以的。这会打断它下面的每个jquery。你可以现场看到这个问题

此外,还提供了指向js文件的直接链接

此功能用于过滤重复的
月份
从本页li上的所有
数据mes
属性中获取。。。我不知道为什么会发生这种情况,我也在用这个:

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

但是,在这个问题上,单独地没有效果

以下是此问题的完整代码:

// 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));

});
//将所有“数据mes”放入一个数组中
var months=$('#grid li').map(函数(){return$(this.data('mes');}).get();
//去除重复的肠系膜
months=months.filter(函数(e,p){return months.indexOf(e)==p;});
//对月份进行排序
var顺序=[‘janeiro’、‘fevereiro’、‘março’、‘abril’、‘maio’、‘junho’、‘julho’、‘agosto’、‘setembro’、‘outubro’、‘Novenbro’、‘dezembro’];
orderedMonths=months.sort(函数(a,b){returnorder.indexOf(a)-order.indexOf(b);});
//将它们按顺序添加到id为#selectMes的
$.each(orderedMonths,function(v,v){
$('#selectmes').append($('
  • ).val(v).text(v)); });
  • indexOf
    不适用于IE。请编写自己的,或者因为您的网页中已经有jQuery。使用jQuery方法:

    如果IE的话,indexOf在很多版本中都不可用。请查看jQuery的inArray:

    使用jQuery

    months = months.filter(function(e, p) { return $.inArray(e, months) == p });
    
    IE9下不支持

    您对array.filter也有问题,因为filter在下面的IE9中不起作用,所以使用


    谢谢。。我现在正在阅读关于inArray()的文章,你能帮我将month=行“转换”为inArray()而不是indexOf吗?我用这部分的完整js编辑了这个问题,如果你能回答的话look@user1576978你可能会犯什么错误?试试这个
    months.filter(函数(e,p,arr){return$.inArray(e,arr)==p})嗯,实际上我不得不更改两行有indexOf()的代码,所以可能我做错了什么,我是这样做的:你能做一个
    控制台.log(JSON.stringify(months))
    并将它粘贴到这里[“julho”,“julho”,“junho”,“junho”,“junho”,“junho”]
    months = months.filter(function(e, p) { return $.inArray(e, months) == p });
    
     months = $.grep(months,function(e, p) { return $.inArray(e, months) == p });