我有一張桌子。每行有一個用於圖像上傳的單元格。我想顯示預覽。爲此,我寫了下面的代碼:上傳之前的預覽圖
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]' –