c***@sina.com
c***@sina.com
  • 发布:2017-12-18 16:39
  • 更新:2017-12-18 16:44
  • 阅读:2238

时而出现Uncaught RangeError: Maximum call stack size exceeded.不知道问题出现在哪里?

分类:HTML5+

当选择超过3M的大图的时候,有时会出现Uncaught RangeError: Maximum call stack size exceeded.程序卡死,最后导致疯狂耗电到手机关机。为了方便代码不乱,也顺便截了张图。

function pickImage() {
var width = document.querySelector('.img-all').offsetWidth + 'px';
var $ul = document.querySelector('#photo-list');
var $add_btn = document.getElementById("add-btn");
// 从相册中选择图片
plus.gallery.pick(function(e) {
if(e.files.length <= 0) return false;
for(var i = 0; i < e.files.length; i++) {
//去重复,并且保证只有6张图片
var path = e.files[i];
if(images.indexOf(path) === -1 && images.length < 6) {
images.push(path);
var liTag = document.createElement('li');
liTag.className = 'img-all';
liTag.setAttribute('style', 'background: url(' + path + ') center/cover no-repeat;width:' + width + ';height:' + width);

            var iTag = document.createElement('i');  
            iTag.setAttribute("id", path);  
            iTag.className = 'img-item-del';  
            liTag.appendChild(iTag);  
            $ul.insertBefore(liTag, $add_btn);  
        }  
    }  
    if(images.length >= 6) {  
        $add_btn.style.display = 'none';  
    }  
},  
function(e) {}, {  
    filter: 'image',  
    multiple: true,  
    system: false  
});  

}

2017-12-18 16:39 负责人:无 分享
已邀请:
回梦無痕

回梦無痕 - 暂停服务

这个报错应该是代码死循环,大量循环或者大量递归引起的。自己检查代码吧

  • c***@sina.com (作者)

    我知道是死循环或者递归,关键是找不出问题所在啊

    2017-12-18 16:47

  • 回梦無痕

    回复 c***@sina.com:你把你代码里的循环改一下

    for(var i in e.files){

    var path = e.files[i]

    }

    2017-12-18 16:50

该问题目前已经被锁定, 无法添加新回复