我有一张桌子。每行有一个用于图像上传的单元格。我想显示预览。为此,我写了下面的代码:上传之前的预览图
var cell8 = row.insertCell(6);
var t8 = document.createElement("input");
t8.type = "file";
t8.id = "img" + index;
t8.name = "img" + index;
var a = document.getElementById('blah_img' + index + '');
a.src = window.URL.createObjectURL(this.files[0]);
t8.onchange = a.src;
cell8.appendChild(t8);
var oImg = document.createElement("img");
oImg.setAttribute('src', 'noimg.png');
oImg.setAttribute('alt', 'your image');
oImg.setAttribute('height', '100');
oImg.setAttribute('width', '100');
oImg.id = "blah_img" + index;
cell8.appendChild(oImg);
在运行它给了我一个错误:
Uncaught TypeError: Cannot read property '0' of undefined.
什么是错在我的代码?请帮忙。
哪条线给出了这个错误? –
window.URL.createObjectURL(this.files [0]) – Rose
什么是'this'旨在引用?尝试't8.files [0]' –