var eSpread, eWrap;
eWrap = document.querySelectorAll('.list-group-item[ng-repeat]');
eWrap.forEach(function(item) {
eSpread = document.createElement('i');
eSpread.classList.add('cus-glyphicon', 'glyphicon-menu-down');
eSpread.addEventListener('click', function(event) {
event.preventDefault();
event.stopPropagation();
angular.element(item).toggleClass('spread');
}, true);
item.appendChild(eSpread);
});
eWrap = document.querySelectorAll(’.list-group-item[ng-repeat]’);
在谷歌和360極速瀏覽器的極速模式下,都顯示eWrap是個nodeList,但在360下報錯。
查找資料信息
querySelectorAll的兼容性
forEach的兼容性
nodeList.forEach
最近發生該錯誤的版本是:谷歌瀏覽器47;
eWrap是有值的,是一個nodeList,僞數組;
forEach是用來遍歷數組的,但也可以遍歷nodeList;
eWrap.forEach在谷歌中報錯,但在ie11中就忽略掉了;
因此,這個問題就是瀏覽器兼容性問題了,解決辦法有兩種:
1、把僞數組轉化爲一個數組;
2、使用兼容性更高的api,比如angular.foreach();
3、在HTML的集合的上下文裏先聲明是一個數組,比如下面的方法:
[].forEach.call(eWrap, function(item) { }