这是我目前的代码。我不确定如何访问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();
});
答案 0 :(得分:2)
尝试使用this.files
,因为:
....
imageSlots.fileInput.on('change', function(e){
console.log(e);
imageSlots.imgNode.src = URL.createObjectURL(this.files[0]);
});
....