Javascript筛选器无法在IE上运行

时间:2018-08-21 09:35:04

标签: javascript filter

希望我能把我的头发剪下来,能对你有所帮助。出于某种原因,以下代码中的过滤器不适用于IE,但适用于所有其他浏览器。

values = values.filter( (val => val.value !== $(this).val()) && (val => val.name !== $(this).attr("name") ) );

下面是隐藏和显示文本区域的完整功能。 但是过滤器链接到计数,因此当清单上没有缺陷时,文件上传框就会出现。

var values = [];
$('input[type="radio"][data-show]').change(function() {
  if ($(this).is(':checked')) {
    var value = {
      "value": $(this).val(),
      "name": $(this).attr("name")
    };

    values = values.filter((val => val.value !== $(this).val()) && (val => val.name !== $(this).attr("name")));

    values.push(value);

    console.log(values);
    var count = 0;
    var non_defect_filtered = values.filter(function(d) {
      count++;
      return d.value === '2';
    });
    var count1 = 0;
    var defect_filtered = values.filter(function(d) {
      count1++;
      return d.value === '1';
    });
    //console.log(filtered.length);

    if ($(this).val() === '1') {
      $(this).closest('div').nextAll('div[data-shown=true]:first').show('slow');
      $(this).closest('div').nextAll('div[data-shown=true]:first').children('.required_input').prop('required', true);
      $('.file_uploader').show('slow');

    } else if ($(this).val() === '2') {
      $(this).closest('div').nextAll('div[data-shown=true]:first').hide('slow');
      $(this).closest('div').nextAll('div[data-shown=true]:first').children('.required_input').prop('required', false);

    }

    if (non_defect_filtered.length === values.length) {
      $('.file_uploader').hide('slow');
    }
    if (defect_filtered.length >= 5) {
      $('.call_fleet').show('slow');
    } else {
      $('.call_fleet').hide('slow');
    }
  }
});

所以人们知道下面的代码过滤器解决了此问题,因为=>不适用于我从未使用过的IE。

var _this = this;
values = values.filter(
(function (val) { 
    return val.value !== $(_this).val();
}) 
&& 
(function (val) {
    return val.name !== $(_this).attr("name"); 
}));

0 个答案:

没有答案
相关问题