360极速浏览器中的极速模式下,报错:forEach is not a function
2017-08-10 11:17
441 查看
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下报错。
查过了一些资料,显示可以这么写,就不报错了
[].forEach.call(eWrap, function(item) { }
原参考答案是这么解释的:
Node.children is dom collection, not an real array so it doesn't have array methods like forEach(need to fix the case also). So one commonly used solution is to call the array methods with the context as the html collection
我理解的意思是: node.children是一个dom的集合,不是一个真正的数组,所以不能用数组的方法,比如forEach。 一个普遍有用的解决方法就是在HTML的集合的上下文里先声明是一个数组。
相关文章推荐
- TypeError: newRawData.forEach is not a function问题解决
- selenium代理注入模式 this.onXhrStateChange.bind is not a function on session
- xxx.forEach is not a function(DOM集合--类数组对象转化为数组)
- ExtJS4 reader.read is not a function
- TypeError: db.collection is not a function
- mongodb 添加用户报错TypeError:db.addUser is not a function
- AngularJS Error: [ng:areq] loginController is not a function
- $(...).niceScroll is not a function
- getfullyear is not a function
- React.createClass is not a function
- $(...).modal is not a function
- 函数索引 ORA-30553: The function is not deterministic 解决方法
- 微信小程序——Error之util.randomString is not a function
- 出现$(#form).validate is not a function的问题
- selenium:org.openqa.selenium.WebDriverException: f.QueryInterface is not a function
- this.getColumnModel is not a function Extjs 如何解决呢? Extjs 导出 到Excel 解决方案问题
- formEl.submit is not a function的原因
- TypeError: n.apply is not a function
- 在form表单里不要出现submit等关键词,否则调用form.submit();会出现form.submit is not a function的错误;
- $http.get is not a function