【发布时间】:2018-04-04 22:01:28
【问题描述】:
function redrawButtonToolbar() {
//debugger;
var buttonYears = window.availableButtonYears;
$(".year-btn").removeClass('hidden').each(function(index) {
var yearBtn = $(this).find('input').val();
console.log("buttonYears: " + buttonYears + " yearBtn: " + yearBtn);
if(yearBtn === 'all') {
return
}
if(!buttonYears.indexOf(yearBtn) !== -1) {
$(this).addClass('hidden')
return
}
})
}
** 从另一个函数调用
window.availableButtonYears = _.uniq(_.map(_.filter(window.data, selectionFilter), "Year"));
当我运行调试器时,我得到以下值存储在 window.availableButtonYears 2014, 2015, 2016
以上代码在 Chrome 中运行良好,但在 IE11 中无法运行。
更新 来自console.log
buttonYears: 2014,2015,2016 yearBtn: all
buttonYears: 2014,2015,2016 yearBtn: 2017
buttonYears: 2014,2015,2016 yearBtn: 2016
buttonYears: 2014,2015,2016 yearBtn: 2015
buttonYears: 2014,2015,2016 yearBtn: 2014
【问题讨论】:
-
控制台有错误吗?你有没有运行 console.log() 看看有什么不同?
-
控制台中没有错误或警告。
-
所以
console.log(buttonYears);和console.log(yearBtn)和console.log(buttonYears.indexOf(yearBtn), !buttonYears.indexOf(yearBtn))找出原因...... -
更新代码并从 console.log 生成输出
-
您使用新错误
!buttonYears.indexOf(yearBtn) !== -1更新了您的代码,并且更改原始代码以使用其中一个答案并不总是最好的做法。
标签: javascript jquery google-chrome internet-explorer-11