站内搜索:
首页 >> 前端 >> 内容
部分低版本浏览器NodeList不支持forEach函数问题的解决办法

时间:2018/6/12 15:00:29

前些天做兼容的时候,一些低版本的浏览器NodeList不支持forEach函数。

解决方案

为不支持forEach函数的浏览器手动添加forEach函数

/**
 * 为nodelist添加forEach函数
 */
function addForEachToNodeList () {
    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)
            }
        }
    }
}

  • 上一篇:tomcat中乱码问题的解决办法
  • 下一篇:vscode更新之后rg.exe占用cpu过高的问题解决
  • 返回顶部