Javascript 对象没有';无法管理forEach属性
我有一个使用forEach方法的脚本,它可以在一些Firefox浏览器上工作,但从来没有在IE11上工作过 错误是:对象不管理forEach属性Javascript 对象没有';无法管理forEach属性,javascript,arrays,foreach,Javascript,Arrays,Foreach,我有一个使用forEach方法的脚本,它可以在一些Firefox浏览器上工作,但从来没有在IE11上工作过 错误是:对象不管理forEach属性 var clearContent = function clearContent() { var allDistricts = document.querySelectorAll(".district"); allDistricts.forEach(function(item) { item.style.display = "none"
var clearContent = function clearContent() {
var allDistricts = document.querySelectorAll(".district");
allDistricts.forEach(function(item) {
item.style.display = "none";
});
};
哦,我可以很容易地替换forEach的方法吗?
感谢对循环使用简单的
:
var clearContent = function clearContent() {
var allDistricts = document.querySelectorAll('.district');
for (var i=0; i<allDistricts.length; i++) {
allDistricts[i].style.display = 'none';
}
};
var clearContent=函数clearContent(){
var allDistricts=document.querySelectorAll('.district');
for(var i=0;iNodeList.queryselectoral
是一个在过时浏览器上不受支持的新函数。(queryselectoral
返回一个NodeList
)
它最初是在Chrome 51和FF 50上支持的,这两个版本在几年前才发布(当然,在2013年发布的IE上根本不支持)
对于多边形填充,可以使用以下方法:
if (window.NodeList && !NodeList.prototype.forEach) {
NodeList.prototype.forEach = function (callback, thisArg) {
thisArg = thisArg || window;
for (var i = 0; i < this.length; i++) {
callback.call(thisArg, this[i], i, this);
}
};
}
if(window.NodeList&!NodeList.prototype.forEach){
NodeList.prototype.forEach=函数(回调,thisArg){
thisArg=thisArg | |窗口;
for(var i=0;i
这是如何解决错误的错误是:对象没有管理前面提到的forEach属性
?如果他使用polyfill,他将能够在节点列表
上使用forEach
。感谢您的帮助:)谢谢,确实问题不在于forEach,而在于querySelectorAll。