这是我目前的代码。我不确定如何访问 jquery 对象或事件的 .files 数组。
var imageSlots = {
crx: null,
fileInput: $('<input type="file"/>'),
imgNode: new Image,
editingSlot: 1,
slot1: null,
slot2: null,
slot3: null,
slot4: null
};
$(document)
.on('ready', function(){
imageSlots.ctx = document.getElementById('editCanvas').getContext('2d');
imageSlots.fileInput.on('change', function(e){
console.log(e);
imageSlots.imgNode.src = URL.createObjectURL(e.files[0]);
});
imageSlots.imgNode.onload = function(){
imageSlots.ctx.drawImage(imageSlots.imgNode, 0,0);
};
})
.on('click', '.image', function(){
imageSlots.fileInput.click();
});
最佳答案
尝试使用this.files
,如下:
....
imageSlots.fileInput.on('change', function(e){
console.log(e);
imageSlots.imgNode.src = URL.createObjectURL(this.files[0]);
});
....
关于javascript - 如何访问 .file 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25064092/