代码如下:
$('#pic_selector').change(function (e) {
let myImage = e.target.files[0]
if (!/image\/\w+/.test(myImage.type)) {
alert("请上传正确的图片格式!")
} else {
let myReader = new FileReader()
myReader.readAsDataURL(myImage)
myReader.onload = function () {
$('#pic_selector').css('background-image', 'url(' + myReader.result + ') no-repeat')
}
}
})
上面是一个input type=file类型的输入框,从中拿到文件后想通过FileReader在本地展示出来,执行到
myReader.readAsDataURL(myImage)
的时候,会提示无法执行操作,The object is already busy reading Blobs.
但是我这里只定义了一个FileReadr(),也只调用了一次,并没有在任何循环里面,请问是怎么会抛出这个异常呢?该如何解决.
虽然断点或try-catch能捕获到这个异常(try-catch有时能捕获到,有时不能...),但是依然正确的执行了,并且能够拿到result.